fix encode corruption