Fix two bugs in rule-matching