Refactor and tests.