Implemented encode