refactored connection creation