Previously I did not take the length into consideration. When we have a variable length key, there can be remaining bytes from the previous value, and it will mess up the hash value.