go back to without extendedSort in ResolveSyntax
go back to without extendedSort in ResolveSyntax and move flattenTerms before AddPredicates