Improve disconnect handling.