move flattenTerms before ResolveBinder