factor out session