updated to write utf8 correctly