better handling of closed connections