Decode/Encode functions updated