Put EVERY { on a new line. Put EVERY } on a new line.
Get rid of the excessive blank lines.
Use Tools + Auto Format to properly format the code.
You'll notice that you can't use it now, because you have a mismatch between the number of { and } in your code. YOU need to figure out which ones don't belong.