fixed how numRecords is calculated
Added some diagnostic output