Some minor sorting optimizations