Added handling for empty array