replaced data[i] with val