Decoder and write-out working, plus some basic cleanup