fixed output file bugs