resampling procedure. needs double checking