reintegrated the rest of the rscript
collect term-frequency stats