improved connection handling