Handle UTF-8 encoding correctly

Closes #1