This entire loop body could be sub-functioned.