added logic for 4 rules