Pull out common connect function