move flattenTermsTwo before ResolveFunctions