Is this correct? Shouldn't `lastgood` always be zero to begin with, i.e. this index is the index of "first bad", and so we actually need to copy from 0 to here.