UTF-8 encoding/decoding fixes related to #317