added comments, fixed an issue where the session state was not cleared when exiting the session