move flattenTerms before addKCell
move flattenTerms before addKCell