refactor connection