implemented encoding and decoding