refactor channel code