fix bug in encoding