added encoding and decoding