Refactoring getSession() method