updated encoding and decoding