Added a check for patternSize and removed a useless check.