refactor connection to use channels rather than polling