Make sure the session is closed correctly