Added check for session state before calling router->closeSession