channel: factor out channel functions