Implemented a check to ensure the session properly closes.