Unbreak some tests, fix some bugs.