refactoring motor code, adding new tests