Fix the encoding implementation