Refactor connection