graph building re-written for igraph