Refactor sampler to use iterators