change multiple file writing to one time write in