Refactor.
Refactor.
Add some unit tests.