Do per-rule validation and ruleset validation. Clean up some code.