Factor out createPattern