Refactored session manager code.