Refactoring applyPatternG