Parentheses balance checker ptimization