refactored the action used to parse parens and groups into a utility function