improved the code about the session management