Added slightly more graceful handling of connection errors