adding session management and improve perivous codes