added logic to catch unmatched closing paren