optimized the code of length of last word.