Put `hash(...)` formula into a helper function, and use it when creating the initial hash (below) and here to check the key. That way, the two will never become inconsistent.