Fixed and improved sorting performance (up to 2.75x faster)