faster key_exists function