Updated encoding/decoding