Synchronized motor movement with mutex

Mutexes are used to synchronize the motor movement.

Divded by zero error fixed at line 45-49