refactor, add tests, update readme.

Should now produce expected results on all tests.
k, no worries. i'll look into it later.