Moving the session close code