Split the output files into writing legend, writing encoded string, and writing everything to a file.
Changed lookup to be more typesafe. Fixed error where it doesn't print last segment if too short and not delimiter.
Added a write_reordered method.