Refactoring of sampling.