refactor. add tests.