fixed bug in resampling()