Moved connection code to common file.