refactored fix for session is null issue