Refactor connection class