Use foreach instead of C++-style iterator.
Address review comments.