changed global variables to session-based