Refactoring for new session handling