Improved connection factory.