Optimized list generation code.