Refactored motif code into class, added unit test.