Fix crash when not sorted