Refactored the rule-based method