fixed bug in resampling code