Tests are now done with the cheapest first

When applying a rule, the easiest tests are now performed first, to
hopefully save performing expensive lookups for items that wouldn't
match anyway.