Fix encoding for UTF-8 output

Fixes encoding, especially regarding html output with unicode characters.