Refactoring and redesign finished. More tests.