Encode and Decode written