Better way to detect end of array.