fix the problem if token list is longer than pattern