Fix bug in sampling functions.