IIUC, this should be 'to' and not 'until', e.g., see what happens when numNodes=3. This loop is only run for '0'.