Fix a number of problems