Resampling and some other code