fixing invalid pattern bug