fix for writing larger files to prevent a heap overflow.