Changed from iterators, which become invalidated if vector is changed, to classic indexing. Now runs! However, the results are incorrect. Closure seems to work through.