Updated code for networkx capability