I think you can create closure here on promise, nodesToVisit, and currentPageIndex instead of passing them as parameters below -- might be easier to read the code