Fix missing curly braces and adjust some formatting.

Reading some code and noticed some curly braces missing, so fixed it and adjusted the formatting a bit to make things easier to read.

Also my client removed some trailing spaces/tabs, so there's some extra lines adjusted.