Added connection error detection