change while to foreach loop