Added graph building function