refactored resampling