updated with proper js reference
added patternFactory function