fixed get_next_entity()