more elegant loops using foreach