Add tests. Refactor implementation.