refactor the code so it's easier to read from both channels