fixed a bug where '\0' was added at the end of the output file