Added legacy_entity_code and changed legacy_id