Modified to add only unique nodes.