add encode for better compatibility