Issue with Unwind

[
{
"valueId": "3db5fc4f-72c0-4241-9aa5-71b74f5d13d1",
"id": "5900955d-058e-440e-8f6e-33e59dd55b22",
"type": "Module"
}
,
{
"valueId": "b40811ec-4485-48fb-896b-646348f600b3",
"id": "9ae46583-6a56-465d-97ff-0ed6085f00e7",
"type": "Module"
}
,
{
"valueId": "9c434bf2-9ce3-475b-bf35-2a5712d5d765",
"id": "fcb0d316-2dfc-44f8-8968-de671e49ca50",
"type": "Physical-Struct"
}
]

CALL apoc.load.json("file:///Value.json") YIELD value as valueMap
MATCH(d:DataEntity{id:'5258e214-b445-41d8-ad60-eb1590228121'})
UNWIND valueMap as value
MATCH(a:AtsEntity{id: value.id})
MATCH(v:ValueEntity{id: value.valueId})
MATCH(d)-[:contains]->(existingAsset:AtsEntity{type: value.type})
WITH a, v, value, collect(toInteger(split(reverse(existingAsset.name), '-')[0])) as nameArray
WITH a, v, value, apoc.coll.max(nameArray) AS prevCount WITH a, v, value, CASE prevCount WHEN NULL THEN 1 ELSE prevCount+1 END as actualCount
SET a.name = a.type+'-'+ actualCount
SET v.targetValue=a.type+'-'+ actualCount

I'm trying to load and unwind above json for setting some node property but it's not updating the correct value

DataEntity will contains AtsEntity
AtsEntity nodes will contains name property as "Module-1", "Module-2", "Module-4" something like that.
We have to set the name property of the coming AtsEntity from json with the max count with suffix AtsEntity type
Example: If same type of AtsEntity has name like "Module-1", "Module-2", "Module-4" then the coming AtsEntity
name would be "Module-5".

Assume that we have 3 nodes with AtsEntity label with 2 node type is "Module" and another type is "Physical-Struct"
1. Label:AtsEntity, name: Module-1, type: Module
2. Label:AtsEntity, name: Module-2, type: Module
3. Label:AtsEntity, name: Physical-Struct-1, type: Physical-Struct
So if we will load the above json and try to excute the query then query should update the name like
1. name: Module-3
2. name: Module-4
3. name: Physical-Struct-2
But the above query is updating the name with
1. name: Module-3
2. name: Module-3 (This should be Module-4)
3. name: Physical-Struct-2

Not sure what I'm missing here please help!!