templatized channel mapping and nearest filter functions. cleaned up a
lot of other stuff