major refactoring to use session object