added logic for the rules.