better handling of connection errors