Fixed buildGraph() method