Enhanced a function to iterate over a list an automatically save correct data