modified to make the processing more efficient and to sort categorizes by frequency and first word.