most of the required code for sessions