refactor unicode encode/decode