Fixed writing to file.