Added checks for unbalanced braces, brackets and parentheses.