Fix hashcode on objects (mean one)

Main change is in object2key (+callers).
Change in _cast is cosmetic (exception cases handled first and
indentation of the rest).