Optimizing sampling