Bunch of more tests and fixes