more idiomatic use of foreach