refactor, add tests, update readme.

Should now produce expected results on all tests.
oh, and add your name to the actual license file too ;)