You can use this page to debug Javascript where you are having problems with { and }. Paste the code into the first box and click on the button. It will reproduce the code, but put a number by each curly bracket. This goes up and down with the nesting. Check that the last closed curly bracket in each function is 1.