Fixing writing to arbitary files