Refactored a lot more javascript in graph.js