Updated as the loop was wrong