Some fixes in session management