use iterator instead of list building