Added Hash#key_index, and use it in some places