simplify code to foreach.'