added a for loop
merged the code together so that both loops work