refactor, add tests, update readme.

Should now produce expected results on all tests.
I personally prefer being explicit on things like this and rather have it fail on nested arrays.