Fix a bunch of minor bugs