Optimised the file output code.