minor fix for encode function, and the deserialize function