Does the logic in this loop need to duplicate the logic in the loop above?  Or could it be moved into a common helper?