Fixed writing multiple times to same file.