Optimized sort