lots of fixes + tests.