prevents foreach from running if array is empty