Lets remove this variable, and just add a counter. If something won't work, it's up to us to re-execute the script with the nid argument.