improved connection error handling