major speedup for the get_key method