Refactored addEdge