Lots of syntax and formatting fixes