move flattenTerms before AddTopCellConfig