move flattenTerm before FlattenSyntax