Revert "refactor a loop"

This reverts commit 5586b95fb4c0a7dd464840fa5c10cadff32a757b.