Refactor channel code