properly handle ended connections