Fixed issue where the sorting logic could blow up.