Fix for deep nested hashes

The previous approach worked when the top-most hash in the nested hash
being set was nil. For any other scenario, that logic didn't work. This
makes the approach more readable, and also more complete.