move flattenTerms before CompileDataStructures
move flattenTerms before CompileDataStructures