refactor, add tests, update readme.

Should now produce expected results on all tests.
to each his own lol, I can move it