Made some corrections to the resampling step.