Adding changes for writing output file