Fix pattern matching bug