fix bug in resample, it resampled only the first trial