Various fixes and tests.