Add checkBrackets to verify balancing of brackets