Refactor rules

We think we're going to add more rules, so it is definitely time to refactor this to make it more readable.