More tests and fixes