Bunch more tests. Some bug fixes