Change foreach to for