Add function key_by, update function _instances_with_id_as_key