Refactor out session code

Change-Id: Id31586a4ffcb1bf036fbbe93837d709fdaab2cee