fixed bug for bracket matching algorithm