Cleaning up the word sort routine.