Fix syntax error and tidy up networkx usage.