Fix a bunch of problems that I somehow managed to miss when testing the previous commit.