changed output file handling to have UTF-8 encoding