implemented the sorting of words.