Updated session handling and refactored util funcs