improve utf8 writing and proper batch file flushing