Various fixes (all tests pass on my machine now).