optimized reduce