fixed file write error