improve enclosed parenthesis parsing
add safe logic if closing parenthesis is missing.