Refactore Connection factory