fix foreach loop

research indicated that my foreach loop was not only syntactically
incorrect, but also ineffectual compared to this new implementation