Refactor connection allocation