New implementation to solve problem with parenthesis