Fix some obvious problems in the code