Fix tests

This fixes a bunch of tests (not all of them yet though). Each commit fixes a separate thing, but I haven't submitted them separately as it was easier to work on a single branch when I was in the train (and it will be easier to see the difference in the test results.
Agreed.