Why is this code within the foreach loop? (lines 122 to 131)