beefed up the sorting