move FlattenTerms before flattenModule