diff --git a/chessboard.module b/chessboard.module
index 566eaad..33901ea 100644
--- a/chessboard.module
+++ b/chessboard.module
@@ -114,38 +114,89 @@ function chessboard_process_chessboard_notation($elements) {
  */
 function chessboard_element_info() {
   $types = array();
+  $image_directory_path = drupal_get_path('module', 'chessboard') . '/default';
+  $dimensions = array(
+    'square' => array(
+      'width' => 40,
+      'height' => 40,
+    ),
+    'border-h' => array(
+      'width' => 40,
+      'height' => 4,
+    ),
+    'border-v' => array(
+      'width' => 4,
+      'height' => 40,
+    ),
+    'border-c' => array(
+      'width' => 4,
+      'height' => 4,
+    ),
+  );
+  $class_attributes = array(
+    'square' => array(
+      'class' => 'chessboard-square',
+    ),
+    'border-h' => array(
+      'class' => 'chessboard-border-h',
+    ),
+    'border-v' => array(
+      'class' => 'chessboard-border-v',
+    ),
+    'border-c' => array(
+      'class' => 'chessboard-border-c',
+    ),
+  );
   $types['chessboard_diagram'] = array(
     '#attached' => array(
       'css' => array(
         drupal_get_path('module', 'chessboard') . '/chessboard.css' => array('media' => 'all', 'preprocess' => FALSE),
       ),
     ),
-    '#dimensions' => array(
-      'square' => array(
-        'width' => 40,
-        'height' => 40,
-      ),
-      'border-h' => array(
-        'width' => 40,
-        'height' => 4,
-      ),
-      'border-v' => array(
-        'width' => 4,
-        'height' => 40,
-      ),
-      'border-c' => array(
-        'width' => 4,
-        'height' => 4,
-      ),
-    ),
+    '#dimensions' => $dimensions,
     '#file_max' => 8,
-    '#image_directory_path' => drupal_get_path('module', 'chessboard') . '/default',
+    '#image_directory_path' => $image_directory_path,
     '#item' => NULL,
     '#pre_render' => array('chessboard_process_chessboard_notation'),
     '#prefix' => '<div class="chessboard">',
     '#suffix' => '</div>',
     '#theme' => 'chessboard',
   );
+  // Construct the translation table
+  $size_attributes = $dimensions;
+
+  // Empty and marked squares
+  $table_tiles = array(
+    '-0' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename('-', 0), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => '-', '#title' => '', '#attributes' => $class_attributes['square']),
+    '-1' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename('-', 1), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => '-', '#title' => '', '#attributes' => $class_attributes['square']),
+    'x0' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename('x', 0), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => 'x', '#title' => '', '#attributes' => $class_attributes['square']),
+    'x1' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename('x', 1), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => 'x', '#title' => '', '#attributes' => $class_attributes['square']),
+  );
+
+  // Pieces
+  $pieces = 'kqbnrp';
+  for ($i=0; $i<6; $i++) {
+    $piece = $pieces[$i];
+    $table_tiles += array(
+      strtoupper($piece) . '0' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename(strtoupper($piece), 0), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => strtoupper($piece), '#title' => '', '#attributes' => $class_attributes['square']),
+      strtoupper($piece) . '1' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename(strtoupper($piece), 1), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => strtoupper($piece), '#title' => '', '#attributes' => $class_attributes['square']),
+      $piece . '0' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename($piece, 0), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => $piece, '#title' => '', '#attributes' => $class_attributes['square']),
+      $piece . '1' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename($piece, 1), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => $piece, '#title' => '', '#attributes' => $class_attributes['square']),
+    );
+  }
+
+  // Borders
+  $table_tiles += array(
+    'T' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('T'), '#width' => $size_attributes['border-h']['width'], '#height' => $size_attributes['border-h']['height'], '#title' => '', '#attributes' => $class_attributes['border-h']),
+    'B' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('B'), '#width' => $size_attributes['border-h']['width'], '#height' => $size_attributes['border-h']['height'], '#title' => '', '#attributes' => $class_attributes['border-h']),
+    'L' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('L'), '#width' => $size_attributes['border-v']['width'], '#height' => $size_attributes['border-v']['height'], '#title' => '', '#attributes' => $class_attributes['border-v']),
+    'R' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('R'), '#width' => $size_attributes['border-v']['width'], '#height' => $size_attributes['border-v']['height'], '#title' => '', '#attributes' => $class_attributes['border-v']),
+    'TL' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('TL'), '#width' => $size_attributes['border-c']['width'], '#height' => $size_attributes['border-c']['height'], '#title' => '', '#attributes' => $class_attributes['border-c']),
+    'TR' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('TR'), '#width' => $size_attributes['border-c']['width'], '#height' => $size_attributes['border-c']['height'], '#title' => '', '#attributes' => $class_attributes['border-c']),
+    'BL' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('BL'), '#width' => $size_attributes['border-c']['width'], '#height' => $size_attributes['border-c']['height'], '#title' => '', '#attributes' => $class_attributes['border-c']),
+    'BR' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('BR'), '#width' => $size_attributes['border-c']['width'], '#height' => $size_attributes['border-c']['height'], '#title' => '', '#attributes' => $class_attributes['border-c']),
+  );
+  $types['chessboard_diagram']['#table_tiles'] = $table_tiles;
   return $types;
 }
 
diff --git a/chessboard_render.php b/chessboard_render.php
index 9a123ce..45c1b8e 100644
--- a/chessboard_render.php
+++ b/chessboard_render.php
@@ -9,56 +9,7 @@ function template_preprocess_chessboard(&$variables) {
 
   $image_directory_path = $variables['element']['#image_directory_path'];
   if (!isset($tables_xhtml[$image_directory_path])) {
-    $class_attributes = array(
-      'square' => array(
-        'class' => 'chessboard-square',
-      ),
-      'border-h' => array(
-        'class' => 'chessboard-border-h',
-      ),
-      'border-v' => array(
-        'class' => 'chessboard-border-v',
-      ),
-      'border-c' => array(
-        'class' => 'chessboard-border-c',
-      ),
-    );
-    $size_attributes = $variables['element']['#dimensions'];
-
-    // Construct the translation table
-
-    // Empty and marked squares
-    $table_tiles = array(
-      '-0' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename('-', 0), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => '-', '#title' => '', '#attributes' => $class_attributes['square']),
-      '-1' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename('-', 1), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => '-', '#title' => '', '#attributes' => $class_attributes['square']),
-      'x0' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename('x', 0), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => 'x', '#title' => '', '#attributes' => $class_attributes['square']),
-      'x1' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename('x', 1), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => 'x', '#title' => '', '#attributes' => $class_attributes['square']),
-    );
-
-    // Pieces
-    $pieces = 'kqbnrp';
-    for ($i=0; $i<6; $i++) {
-      $piece = $pieces[$i];
-      $table_tiles += array(
-        strtoupper($piece) . '0' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename(strtoupper($piece), 0), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => strtoupper($piece), '#title' => '', '#attributes' => $class_attributes['square']),
-        strtoupper($piece) . '1' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename(strtoupper($piece), 1), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => strtoupper($piece), '#title' => '', '#attributes' => $class_attributes['square']),
-        $piece . '0' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename($piece, 0), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => $piece, '#title' => '', '#attributes' => $class_attributes['square']),
-        $piece . '1' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_piece_filename($piece, 1), '#width' => $size_attributes['square']['width'], '#height' => $size_attributes['square']['height'], '#alt' => $piece, '#title' => '', '#attributes' => $class_attributes['square']),
-      );
-    }
-
-    // Borders
-    $table_tiles += array(
-      'T' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('T'), '#width' => $size_attributes['border-h']['width'], '#height' => $size_attributes['border-h']['height'], '#title' => '', '#attributes' => $class_attributes['border-h']),
-      'B' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('B'), '#width' => $size_attributes['border-h']['width'], '#height' => $size_attributes['border-h']['height'], '#title' => '', '#attributes' => $class_attributes['border-h']),
-      'L' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('L'), '#width' => $size_attributes['border-v']['width'], '#height' => $size_attributes['border-v']['height'], '#title' => '', '#attributes' => $class_attributes['border-v']),
-      'R' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('R'), '#width' => $size_attributes['border-v']['width'], '#height' => $size_attributes['border-v']['height'], '#title' => '', '#attributes' => $class_attributes['border-v']),
-      'TL' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('TL'), '#width' => $size_attributes['border-c']['width'], '#height' => $size_attributes['border-c']['height'], '#title' => '', '#attributes' => $class_attributes['border-c']),
-      'TR' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('TR'), '#width' => $size_attributes['border-c']['width'], '#height' => $size_attributes['border-c']['height'], '#title' => '', '#attributes' => $class_attributes['border-c']),
-      'BL' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('BL'), '#width' => $size_attributes['border-c']['width'], '#height' => $size_attributes['border-c']['height'], '#title' => '', '#attributes' => $class_attributes['border-c']),
-      'BR' => array('#theme' => 'image', '#path' => $image_directory_path . '/' . chessboard_border_filename('BR'), '#width' => $size_attributes['border-c']['width'], '#height' => $size_attributes['border-c']['height'], '#title' => '', '#attributes' => $class_attributes['border-c']),
-    );
-    foreach($table_tiles as $code => $tile) {
+    foreach($variables['element']['#table_tiles'] as $code => $tile) {
       $tables_xhtml[$image_directory_path][$code] = drupal_render($tile);
     }
   }
