It would help if you formatted your code more clearly. Use one } per line to end a block, and indent it by the same amount as the line that began the block.