fixed encode func in sample script