fixing optimized maximal sort