Just a nit-pick, but you should check if the length of the array is greater than zero before you choose the first element.