Refactor 'generate parentheses'.