added some code for detecting user session