separated out connection function