Refactor channel handler