Fixed bug in sampling.