cleaned up Graph.js code and DRY-ed it up a ton