[major] Better code-reuse by doing the client during the `close` event.

Would love to get a second pair of eyes on this change. It would promote better code re-use but I don't know if I enable any race conditions or edge cases to exists as the clean up is now only done when the `close` event is emitted.