Stricter rules for second pass.
Refactored matching code.