Added logic for rules