Added conditional write for addEdge