I would include after line 256 the lines
```
search.setHandler("done", function(obj, lookupItem) {
   finalize();
});
```
Is this what you want?