improved disconnect handling