Added code to detect unbalanced parenthesis