Added comments and optimizations to dotgraph code