Fixed bug when receiving a specific case of unbalanced parenthesis.
This commit also adds more test cases.