lots of new tests and fixes