Change in isMatchedPattern method, using for each instead of iterator