Refactored trimming out of demultiplexing.

This should make it easier to swap in new trimming algorithms
in the future.