unoptimized word sorting function.