flatten: replace id, instead of using flat_id