Avoided creating a set from the list on each iteration