Merge both connect functions into 1.