extracted get_entities method