di.id is uninitialized in the first loop. Move it to the second loop
Fix typo and compilation error