fixed bugs when session is closed.