move channels_mask cleaning at the end