A bunch of syntax and error fixes