Avoid creating word_freqs outside and passing it around.

In order to about side effects at all, the word_freqs variable is not created from outside and pass it around. Instead, it is returned by one of the functions.