Moved most of the global session information into a new session struct and then changed functions accordingly