use foreach instead of C-style for loop