Improve graph implementation