Patch - Change file writing to more effective