Completed the addEdge function