Refactoring for session management.