Fix Encode and Decode