Refactor matching_rules