Week4,5: implemented encoding/decoding