Refactor motor functions: move common functionality to _set_motor.
Some minor changes.