move flattenTerms before addStreamCell