Added fully working function countFreqs