Refactored out the pattern adding into a helper function