Fixing bug where pre-processed segment would not be fully pre-process.
Fix some of the tests, for green build
Refactor this code to limit duplication.