more idiomatic foreach instead of for loops