Add consistency checks to pattern matching