Better hash function

No more undefined, more useful use of the available polymorphism.