lots of fixes, more tests