Some fixes for the session code.

Before the `_cleanup` method was not actually called when `stream.end()` was called.