Added better error checking on connection