foreach loop simplification