refactor use of session