fix bug in sampling