First cut at implementing rule ordering so that more specific types are preferred to less specific types based on idea by Anton Tayanovskyy.  The code compiles and seems to run fine, but I have yet to verify that it produces the desired results.