Revert "modified the double foreach"

This reverts commit c157916368ba34991d0e2d892bd02dfd1246959b.
Revert "Revert "modified the double foreach""

This reverts commit 52daf1dc2247a39f7f1b6fdc17e17c6fab2f206a.