fixing bug in encoding, no test yet