Optimized code for graph visualizer app.