Fix bug where multi-byte characters sometimes are not decoded correctly.
(Also avoids converting data to string and back unnecessarily.)