Better handling of multi-byte UTF-8 characters.

This patch should resolve some encoding issues where multi-byte
characters are split between buffers, and not encoded properly.