changed the way to write files