Improved handling of connection errors.