refactored/tested session manager