Fix #31 encode/decode problems