diff --git a/graphapi.module b/graphapi.module
index 01c0990..debefa4 100644
--- a/graphapi.module
+++ b/graphapi.module
@@ -111,21 +111,6 @@ function graphapi_engines_form($form, $form_state, $engine = 'graphapi') {
   return $form;
 }
 
-function _graphapi_demo_graph() {
-  $graph = graphapi_new_graph();
-  graphapi_add_link($graph, "graphapi_relation", "relation");
-  graphapi_add_link($graph, "graphapi_relation", "graphapi");
-  graphapi_add_link($graph, "graphapi", "views");
-  graphapi_add_link($graph, "php", "graphapi");
-  graphapi_add_link($graph, "graphapi", "graph_phyz");
-  graphapi_add_link($graph, "graphapi", "graphviz");
-  graphapi_add_link($graph, "graphapi", "thejit");
-  graphapi_add_link($graph, "thejit", "thejit_spacetree");
-  graphapi_add_link($graph, "thejit", "thejit_forcedirected");
-  graphapi_add_link($graph, "thejit", "thejit_x");
-  return $graph;
-}
-
 /**
  * Creates a new empty graph array.
  */
@@ -619,19 +604,6 @@ function _graphapi_engine_form($engine, $values) {
   return call_user_func($function, $values);
 }
 
-function graphapi_demo_engines($engine = 'graph_phyz') {
-  $graph = _graphapi_demo_graph();
-
-  $config = array(
-    'engine' => $engine,
-    'width' => 400,
-    'height' => 300,
-    'background-color' => '#AAA',
-    'duration' => 400,
-  );
-  return theme('graphapi_dispatch', array('graph' => $graph, 'config' => $config));
-}
-
 function _graphapi_mapping_options($engine) {
   $node_options = graphapi_node_properties($engine);
   $opts = array(
diff --git a/modules/graph_phyz/graph_phyz.module b/modules/graph_phyz/graph_phyz.module
index e1267ff..68d81c1 100644
--- a/modules/graph_phyz/graph_phyz.module
+++ b/modules/graph_phyz/graph_phyz.module
@@ -170,16 +170,16 @@ function template_preprocess_views_graphapi_style_graph_phyz(&$vars) {
 /**
  * Theme implementation, returns graph_phyz container as HTML.
  */
-function theme_graph_phyz_container($variables) {
-  return graph_phyz_container($variables['graph'], $variables['config']);
+function theme_graph_phyz_container($vars) {
+  return graph_phyz_container($vars['graph'], $vars['config']);
 }
 
 /**
  * Theme implementation, returns graph title as HTML.
  */
-function theme_graph_phyz_title($variables) {
-  $title = $variables['title'];
-  $data = $variables['data'];
+function theme_graph_phyz_title($vars) {
+  $title = $vars['title'];
+  $data = $vars['data'];
 
   $attributes = array(
     'class' => 'graphapi-title',
@@ -198,10 +198,10 @@ function theme_graph_phyz_title($variables) {
 /**
  * Theme implementation, returns graph node as HTML.
  */
-function theme_graph_phyz_node($variables) {
-  $dom_id = $variables['dom_id'];
-  $data = $variables['data'];
-  $config = $variables['config'];
+function theme_graph_phyz_node($vars) {
+  $dom_id = $vars['dom_id'];
+  $data = $vars['data'];
+  $config = $vars['config'];
 
   $attributes = array(
     'id' => $dom_id,
@@ -225,24 +225,24 @@ function theme_graph_phyz_node($variables) {
 /**
  * Theme implementation, returns graph edge as HTML.
  */
-function theme_graph_phyz_link($variables) {
+function theme_graph_phyz_link($vars) {
   $html = '<edge';
-  $html.= ' from="' . $variables['from'] . '"';
-  $html.= ' to="' . $variables['to'] . '"';
+  $html.= ' from="' . $vars['from'] . '"';
+  $html.= ' to="' . $vars['to'] . '"';
   if (isset($link['data']['type'])) {
-    $html.= ' type="' . $variables['data']['type'] . '"';
+    $html.= ' type="' . $vars['data']['type'] . '"';
   }
-  if (isset($variables['data']['color'])) {
-    $html.= ' color="' . $variables['data']['color'] . '"';
+  if (isset($vars['data']['color'])) {
+    $html.= ' color="' . $vars['data']['color'] . '"';
   }
-  if (isset($variables['data']['classes'])) {
-    $classes = $variables['data']['classes'];
+  if (isset($vars['data']['classes'])) {
+    $classes = $vars['data']['classes'];
     $class = join(" ", $classes);
     $html.= ' class="' . $class . '"';
   }
   $html.= '>';
-  if (isset($variables['title'])) {
-    $html.= '<a href="#" title="' . $variables['title'] . '">&curren;</a>';
+  if (isset($vars['title'])) {
+    $html.= '<a href="#" title="' . $vars['title'] . '">&curren;</a>';
   }
   $html.='</edge>';
 
@@ -257,9 +257,9 @@ function theme_graph_phyz_link($variables) {
  * @param $config
  *   Graph config array (see graph_phyz_default_config() for details).
  */
-function theme_graph_phyz_links($variables) {
-  $graph = $variables['graph'];
-  $config = $variables['config'];
+function theme_graph_phyz_links($vars) {
+  $graph = $vars['graph'];
+  $config = $vars['config'];
   $result = '<edges>';
   foreach ($graph as $from => $data) {
     foreach ($data['edges'] as $to => $link_data) {
diff --git a/modules/graphapi_demo/graphapi_demo.module b/modules/graphapi_demo/graphapi_demo.module
index e5cb8d7..348ba1f 100644
--- a/modules/graphapi_demo/graphapi_demo.module
+++ b/modules/graphapi_demo/graphapi_demo.module
@@ -47,7 +47,7 @@ function graphapi_demo_page($engine = NULL) {
 function graphapi_demo_engine($engine) {
   $engines = graphapi_views_formats();
   $items = array();
-  $config = graphapi_demo_config();
+  $config = graphapi_demo_config($engine);
   $engine_configs = graphapi_demo_engine_config();
   $graph = graphapi_demo_graph();
 
@@ -76,11 +76,14 @@ function graphapi_demo_engine_config() {
   );
 }
 
-function graphapi_demo_config() {
-  $config = array(
-    'width' => 400,
-    'height' => 400,
-  );
+function graphapi_demo_config($engine) {
+  $config = array();
+  if ($engine == 'graph_phyz') {
+    $config = array(
+      'width' => 400,
+      'height' => 400,
+    );
+  }
   return $config;
 }
 
@@ -106,19 +109,33 @@ function graphapi_demo_graph() {
   graphapi_add_sub_graph($graph, 'S', $sub);
   graphapi_set_node_title($graph, 'S', 'Subgraph if supported');
   graphapi_add_link($graph, 'graphapi', 'A');
-  graphapi_add_link($graph, 'A', 'S');
+  
+
+  $sub2 = _graphapi_demo_subgraph2();
+  graphapi_add_sub_graph($graph, 'S2', $sub2);
+  graphapi_set_node_title($graph, 'S2', 'Test Subgraph');
+  graphapi_add_link($graph, 'F', 'S'); // Subgraph_2.Node -> Subgraph_1
+  graphapi_add_link($graph, 'D', 'S'); // Node -> Subgraph_1
+  graphapi_add_link($graph, 'S', 'S2'); // Subgraph_1 -> Subgraph_2
+  graphapi_add_link($graph, 'G', 'C'); // Subgraph_2.Node -> Subgraph_1.Node
 
   return $graph;
 }
 
 function _graphapi_demo_subgraph() {
   $graph = graphapi_new_graph();
-
   graphapi_add_link($graph, 'A', 'B');
   graphapi_add_link($graph, 'B', 'C');
   return $graph;
 }
 
+function _graphapi_demo_subgraph2() {
+  $graph = graphapi_new_graph();
+  graphapi_add_link($graph, 'D', 'F');
+  graphapi_add_link($graph, 'E', 'G');
+  return $graph;
+}
+
 function _graphapi_demo_module_content($id, $project_id = NULL) {
   $text = '';
   if (is_null($project_id)) {
diff --git a/modules/graphviz/graphviz.info b/modules/graphviz/graphviz.info
index e091b3e..94c66db 100644
--- a/modules/graphviz/graphviz.info
+++ b/modules/graphviz/graphviz.info
@@ -3,5 +3,6 @@ description = A text implementation of the Graphviz data structure
 package = Visualization
 core = 7.x
 dependencies[] = graphapi
+dependencies[] = graphviz_filter
 
 files[] = graphviz.module
diff --git a/modules/graphviz/graphviz.module b/modules/graphviz/graphviz.module
index c944a71..eb967e6 100644
--- a/modules/graphviz/graphviz.module
+++ b/modules/graphviz/graphviz.module
@@ -32,15 +32,6 @@ function graphviz_default_settings() {
 }
 
 /**
- * Implementations of theme_ENGINE_graphapi
- *
- * @param type $vars
- */
-function theme_graphviz_graphapi($vars) {
-  return theme('graphviz_container', $vars);
-}
-
-/**
  * Implements hook_graphapi_default_settings().
  *
  * @see graphviz_default_settings()
@@ -66,15 +57,70 @@ function graphviz_theme() {
         'config' => NULL,
       ),
     ),
+    'graphviz_links' => array(
+      'variables' => array(
+        'graph' => NULL,
+        'config' => NULL,
+      ),
+    ),
   );
 }
 
 /**
- * Implements theme_ENGINE_graphapi().
+ * Implementations of theme_ENGINE_graphapi
+ *
+ * @param type $vars 
  */
-function theme_graphapi_graphviz_graphapi($vars) {
-  $config = $vars['config'];
-  return '<xmp>' . graphviz_to_dot($vars['graph']) . '</xmp>';
+function theme_graphviz_graphapi($vars) {
+  //$config = $vars['config'];
+  //return '<xmp>' . graphviz_to_dot($vars['graph']) . '</xmp>';
+  return theme('graphviz_container', $vars);
+}
+
+/**
+ * Theme implementation, returns graphviz container as HTML.
+ */
+function theme_graphviz_container($vars) {
+  //$dot = graphviz_to_dot($vars['graph']);
+  //return graphviz_filter_filterproc($dot);
+  return graphviz_container($vars['graph'], $vars['config']);
+}
+
+/**
+ * Renders the HTML for the given graph containing the image/svg and divs
+ *
+ * @param $graph
+ *   Graph array.
+ * @param $config
+ *   Graph config array (see graphapi_default_config() for details).
+ */
+function graphviz_container($graph, $config = array()) {
+  $config+= graphapi_default_config();
+  $config['id'] = 'graphapi-' . $config['id'];
+
+  $styles = array(
+  );
+
+  $s = '';
+  foreach ($styles as $style => $value) {
+    $s .= "$style: $value; ";
+  }
+  $attributes = array(
+    'id' => $config['id'],
+    'class' => 'graphapi',
+    'style' => $s,
+  );
+  $a = drupal_attributes($attributes);
+  
+  $nl = "\n";
+  $result = '';
+  $result.= '<div ' . $a . '>';
+  $dot = graphviz_to_dot($graph);
+  $image = graphviz_filter_filterproc($dot);
+  $result.= $nl . $image;
+  $result .= $nl . '</div>';
+
+  return $result;
 }
 
 /**
@@ -90,21 +136,28 @@ function theme_graphapi_graphviz_graphapi($vars) {
  */
 function graphviz_to_dot($graph) {
   $dot = array();
-  $dot[] = "digraph {";
+  $dot[] = "digraph G {";
+  $dot[] = 'graph [fontsize=10 fontname="Verdana" compound=true];';
+  $dot[] = 'node [shape=record fontsize=10 fontname="Verdana"];';
   // TODO: make a proper result
-  //$tree = graphapi_get_graph_tree();
+  // $tree = graphapi_get_graph_tree();
+  // Print nodes
   foreach ($graph as $id => $node) {
     if (isset($node['_subgraph'])) {
       $dot[] = '  subgraph cluster_' . $id . ' {';
+      $dot[] = '    node [style=filled];';
+      $dot[] = '    color=blue;';
+      $subgraph_nodes = '   ';
       foreach ($node['_subgraph'] as $sub_id) {
-        $dot[] = '    ' . 'node_' . $sub_id;
+        $subgraph_nodes .= ' ' . 'node_' . $sub_id;
       }
+      $dot[] = $subgraph_nodes . ";";
     }
     else {
       $dot[] = '  ' . 'node_' . $id . ' [';
     }
 
-    $dot[] = '    label = "' . $node['data']['title'] . '"';
+    $dot[] = '    label = "' . $node['data']['title'] . '";';
 
     if (isset($node['_subgraph'])) {
       $dot[] = '  }';
@@ -113,10 +166,19 @@ function graphviz_to_dot($graph) {
       $dot[] = '  ]';
     }
   }
-
+  // Print links
   foreach ($graph as $id => $node) {
     foreach ($node['edges'] as $eid => $edge) {
-      $dot[] = "  node_$id -> node_$eid";
+      if (empty($graph[$eid]['_subgraph'])) { // node -> node
+        $dot[] = "  \"node_$id\" -> \"node_$eid\";";
+      } elseif (isset($graph[$eid]['_subgraph'])&& empty($graph[$id]['_subgraph'])) { // node -> subgraph
+        $tnode = $graph[$eid]['_subgraph'][0];
+        $dot[] = "  \"node_$id\" -> \"node_" . $tnode . "\" [lhead=cluster_" . $eid . "];";
+      } elseif (isset($graph[$eid]['_subgraph'])&& isset($graph[$id]['_subgraph'])) { // subgraph -> subgraph
+        $tnode = $graph[$eid]['_subgraph'][0];
+        $lnode = $graph[$id]['_subgraph'][0];
+        $dot[] = "  \"node_$lnode\" -> \"node_" . $tnode . "\" [lhead=cluster_" . $eid . " ltail=cluster_" . $id ."];";
+      }
     }
   }
   $dot[] = '}';
@@ -124,13 +186,6 @@ function graphviz_to_dot($graph) {
   return join("\n", $dot);
 }
 
-/**
- * Theme implementation, returns graphviz container as HTML.
- */
-function theme_graphviz_container($vars) {
-  return '<xmp>' . graphviz_to_dot($vars['graph']) . '</xmp>';
-}
-
 function graphviz_graphapi_node_properties() {
   return array(
     'background-color' => 'Background Color',
