Fix a few bugs