bugs in the sampling procedure fixed