fixed write file bugs.