Refactored connection process