counting frequencies of terms