replaced for with foreach