Finished implementing the new way of writing the output files, though their formatting still needs tidying up.