Fix a bunch of small bugs