refactor and use channels