Compute max_freq separately from sorted_words.

This speeds things up in the case where you only ever need to look up frequencies, rather than needing the entire sorted list.