refactored locomotion code into an object