One last commit to fix the possible KeyErrors when closing a session