Added lots of test coverage, not quite complete tho