added session mangment

Added code to handle session and to exit session if logged out