fix writing to a file