Improve disconnection handling

Closes #11