fixed encode for 2.x