Better error checking for connections