using iterator instead of list