Fixed some issues in dealing with multibyte characters.
Merge remote-tracking branch 'upstream/master'