check numrows before running foreach