move flattenTerms back before ResolveOpenCells