Refactor connection-factory, use private function