working key_compare func