Wouldn't it be more straightforward to check that the keys are equal?