Added a test and some refactoring for the 'w' motion code.