Refactor code

Extract the conditions before the loop, as they do not change due to channel definition.

Created by  Nikola Knezevic  on March 26, 2020
F6UHDFJXXDNY5MHXOTH6S33MCSE7RXMQI3ZYJESK4QESFDT4FLLQC
In channels
main
upstream
Change contents