Rewrote record iteration and counting. The code is much cleaner.