fixed the parentheses counter

see my comments in code for explanation