Added a bunch of new tests and fixes