Moved the function creation into the iterator