sorting optimizations