bug fix - check for array before foreach loop