Minor refactoring for new session handling