move flattenTerms before resolveFreshVarMOS