Fix an issue in the ordering of terms