fixed bug in sampling