add parentheses balancing validation algorithm