add disconnection logic

Useful in unit testing other stuff.