fix bugs, write files