separate out the connect code