Adding logic to remove duplicate nodes if any