Cleanups and fixes; make test suite work once more.

Various fixes with the goal of making the test suite pass again.