extracted the connect routine in client code