Fixed issue where parts of the output file would not be written in the FINAL condition