checked for empty variables before foreach