use size-1 instead of lastIndex for #487