Correct a bug in sampling and optimize cum2x