Current implementation will crash if the array is empty. Obviously the test code doesn't cover this edge case.