common create_rule code moved here.