refactor session.rb