move hashing logic up so we get arity information for optimization