factor out sessions code