Refactor and add more tests.
Refactor and add more tests.