Use new encoder for encoding
Use correct unsigned type for utf8 checking