handle empty array correctly