Fix and refactor getSession