Added validation for empty array.