refactor of session, etc