move flattenTerm before ResolveBuiltins
move flattenTerm before ResolveBuiltins