Implemented encode and decode methods