fixed a write out of array bounds while resampling