Various new tests and fixes