This loop was accessing 1 element beyond the end of the vector.