refactor, add tests, update readme.

Should now produce expected results on all tests.
lol k. I guess I should squash at this point, or do you like preserving the history?