nodes.pop(0) is more efficient here