added session handling and database hooks