fixed errors, now works. although les than 3-byte strings are not yet encoded at all.