Incorporate fixes from ariphron
Add fixes to output files