Improve disconnect handling