Working code with network graph