Fix a bunch of mistakes in the code