Improve session-ending error handling

closes #66