better vectorization of resampling/sampling