fix crash when non-utf-8 characters are in strings