Added validation for bracket balancing