Optimize iterating samples