Refactor.
Add unit tests.