changed for lop to foreach to remove dependency on index number