some speedups on sampling