Updated encoding and decoding of token