Some Code runs before other

When I execute a simple program to move forward, open the claw (ClawBot IQ) and move backward. Instead of this, it will move forward, pause, move backward, and then open the claw.

setMotorSpeed(ClawMotor, 100);
sleep(1000);
setMotorSpeed(LeftMotor, 127);
setMotorSpeed(RightMotor, 127);
sleep(1000);
setMotorSpeed(LeftMotor, 0);
setMotorSpeed(RightMotor, 0);
sleep(1000);