Fix the session management and checking