check for empty array before iterating