Refactor session creation code into a private method and use it in both openSession and restoreSession