Started rewriting sorting engine for Material.

It's not pretty but...  I'm sure a lot of it is unneeded.  I'll probably
end up switching back to a comparator, this is just a test using a
TreeMap.