Rewrite graph builder in CoffeeScript