Add unit tests
More refactor and tests