Refactor for tests, add tests, win at tests.