Fix crash if the array is empty.