ensure function doesn't get called when the array is empty