fixed encode/decode bug