fixed encode loop syntax