Make testable and add tests.