Fix a lot of small bugs