without reading the code too closely - that error message usually means you have an imbalance of curly brackets.
in the IDE, put your cursor to each curly bracket - and there will be a matching highlight to show where the other of the pair is.
just keep doing that through your code to make sure you have the curly brackets in the right place.