Added tests.
Refactored for easier testing.
Added more tests.
Fixed lint.