connection establishment with error checking