Revert "Revert "Connection refactoring""

This reverts commit ec3f02873cbf961176d86eb9784b1b75ae763843.