Refactor.
Fix tests.