cleanup iteration, added memoize