fix bug on encode