adding flattenTerms