move flattenTerms out and make java backend back to the origin
move flattenTerms out and make java backend back to the origin