Fixed addEdge function