fix utf8 encoder, add UTF16 surrogate handling