move flattenTerms before AddStreamCells