refactor motor control