Prevent errors when encoding is not utf-8

Fixes issue #64