added finaly encoding and decoding
merged encoding