Bugs/2674/utf8

It's fixing #2674. It also significantly increases performance of UTF encoding.
length not lenth ;)