diff --git a/mailing_label.module b/mailing_label.module
index 18eb644..d422ccc 100644
--- a/mailing_label.module
+++ b/mailing_label.module
@@ -25,13 +25,14 @@ function mailing_label_require_tcpdf() {
 
 function mailing_label_get_formats() {
   mailing_label_require_tcpdf();
+  tcpdf_label::read_xml_labels();
   return tcpdf_label::getAveryFormatOptions();
 }
 
 function mailing_label_tcpdf_label($rows, $format) {
   mailing_label_require_tcpdf();
 
-  $pdf = new tcpdf_label;
+  $pdf = new tcpdf_label($format);
   $pdf->addPage();
 
   foreach ($rows as $row) {
diff --git a/mailing_label_plugin_style_standard.inc b/mailing_label_plugin_style_standard.inc
index fb6a975..7dceb39 100644
--- a/mailing_label_plugin_style_standard.inc
+++ b/mailing_label_plugin_style_standard.inc
@@ -26,7 +26,6 @@ class mailing_label_plugin_style_standard extends views_plugin_style {
 
     // the label format implicitly defines margins, # per page, etc
     $options['label_format'] = array('default' => '5160');
-
     return $options;
   }
 
diff --git a/tcpdf_label.php b/tcpdf_label.php
index eebfcce..bf1c387 100644
--- a/tcpdf_label.php
+++ b/tcpdf_label.php
@@ -9,113 +9,125 @@ class tcpdf_label extends TCPDF {
   private $coord_x = 0, $coord_y = 0;
 
   private $label_format;
-	private static $avery_formats = array(
-		'5160' => array(
-      'paper-size' => 'letter',
-      'unit' => 'mm', // unit for all measurements
-      'marginLeft' => 1.762, // page margins
-      'marginTop' => 10.7,
-      'NX' => 3,    // number of labels across page
-      'NY' => 10,   // number of labels down page
-      'SpaceX' => 3.175,  // space between labels
-      'SpaceY' => 0,
-      'width' => 66.675,  // width of label
-      'height' => 25.4,   // height of label
-      'padding' => 3,     // padding around edge of label
-      'font-size' => 8,   // default font size
-    ),
-    '5161' => array(
-      'paper-size' => 'letter',
-      'metric' => 'mm',
-      'marginLeft' => 0.967,
-      'marginTop' => 10.7,
-      'NX' => 2,
-      'NY' => 10,
-      'SpaceX' => 3.967,
-      'SpaceY' => 0,
-      'width' => 101.6,
-      'height' => 25.4,
-      'font-size' => 8,
-    ),
-    '5162'  =>  array(
-      'paper-size' => 'letter',
-      'metric' => 'mm',
-      'marginLeft' => 0.97,
-      'marginTop' => 20.224,
-      'NX' => 2,
-      'NY' => 7,
-      'SpaceX' => 4.762,
-      'SpaceY' => 0,
-      'width' => 100.807,
-      'height' => 35.72,
-      'font-size' => 8,
-    ),
-    '5163'  =>  array(
-      'paper-size' => 'letter',
-      'metric' => 'mm',
-      'marginLeft' => 1.762,
-      'marginTop' => 10.7,
-      'NX' => 2,
-      'NY' => 5,
-      'SpaceX' => 3.175,
-      'SpaceY' => 0,
-      'width' => 101.6,
-      'height' => 50.8,
-      'font-size' => 8,
-    ),
-    '5164'  =>  array(
-      'paper-size' => 'letter',
-      'metric' => 'in',
-      'marginLeft' => 0.148,
-      'marginTop' => 0.5,
-      'NX' => 2,
-      'NY' => 3,
-      'SpaceX' => 0.2031,
-      'SpaceY' => 0,
-      'width' => 4.0,
-      'height' => 3.33,
-      'font-size' => 12,
-    ),
-    '8600'  =>  array(
-      'paper-size' => 'letter',
-      'metric' => 'mm',
-      'marginLeft' => 7.1,
-      'marginTop' => 19,
-      'NX' => 3,
-      'NY' => 10,
-      'SpaceX' => 9.5,
-      'SpaceY' => 3.1,
-      'width' => 66.6,
-      'height' => 25.4,
-      'font-size' => 8,
-    ),
-    'L7163' =>  array(
-      'paper-size' => 'A4',
-      'metric' => 'mm',
-      'marginLeft' => 5,
-      'marginTop' => 15,
-      'NX' => 2,
-      'NY' => 7,
-      'SpaceX' => 25,
-      'SpaceY' => 0,
-      'width' => 99.1,
-      'height' => 38.1,
-      'font-size' => 9,
-    ),
-    '3422'  =>  array(
-      'paper-size' => 'A4',
-      'metric' => 'mm',
-      'marginLeft' => 0,
-      'marginTop' => 8.5,
-      'NX' => 3,
-      'NY' => 8,
-      'SpaceX' => 0,
-      'SpaceY' => 0,
-      'width' => 70,
-      'height' => 35,
-      'font-size' => 9,
-    )
-  );
+  private static $avery_formats;
+  
+  /**
+  * @brief Convert different size units from label defintions into mm
+  *
+  * @param $input String containing size and possibly units 
+  *               If no unit is included then pt is assumed
+  * @return Size in mm
+  */
+
+  private function unit_conv($input)
+  {
+    list($num,$unit) = sscanf($input,"%f%s");
+    switch ($unit)
+    {
+      case '':
+      case 'pt':
+        $result = $num / 2.834;
+        break;
+      case 'in';
+        $result = $num * 25.4;
+      case 'mm':
+        $result = $num;
+        break;
+    }
+    return $result;
+  }
+                                                                      
+  /**
+  * @brief Read and parse XML definitions of labels
+  *
+  * @param None
+  *
+  * @return No return value
+  */
+
+  function read_xml_labels ()
+  {
+  
+    $module_path = drupal_get_path('module','mailing_label');
+
+    $xml_dir = $module_path . '/templates/';
+
+    $xml_files = glob($xml_dir . '*.xml');  
+
+    foreach($xml_files as $xml_file)  
+    {
+
+      $xml = simplexml_load_file($xml_file);
+
+      foreach($xml->children() as $Template)
+      {
+        $label = (string) $Template['part'];
+        $equiv = (string) $Template['equiv'];
+        if ($equiv)
+        {
+        // Make sure it is not equivalent to a label we have ignored         
+          if (array_key_exists($equiv,self::$avery_formats))
+          {
+            self::$avery_formats[$label] = self::$avery_formats[$equiv];
+            self::$avery_formats[$label]['brand'] = (string) $Template['brand'];
+          }
+        }
+        else
+        {
+          $Label_rectangle = 'Label-rectangle';
+          // Only consider square labels for now
+          if ($Template->$Label_rectangle)
+          {
+/*
+    x0 and y0 are the offsets to first label
+    dx and dy are distance to the next label
+*/
+              $Markup_margin = 'Markup-margin';
+              self::$avery_formats[$label]['paper-size'] = (string) $Template['size'];
+              self::$avery_formats[$label]['brand'] = (string) $Template['brand'];
+              self::$avery_formats[$label]['label-width'] = self::unit_conv((string) $Template->{$Label_rectangle}['width']);
+              self::$avery_formats[$label]['label-height'] = self::unit_conv((string) $Template->{$Label_rectangle}['height']);
+              self::$avery_formats[$label]['nx'] = (integer) $Template->{$Label_rectangle}->Layout['nx'];
+              self::$avery_formats[$label]['ny'] = (integer) $Template->{$Label_rectangle}->Layout['ny'];
+              self::$avery_formats[$label]['x0'] = self::unit_conv((string) $Template->{$Label_rectangle}->Layout['x0']);
+              self::$avery_formats[$label]['y0'] = self::unit_conv((string) $Template->{$Label_rectangle}->Layout['y0']);
+              self::$avery_formats[$label]['dx'] = self::unit_conv((string) $Template->{$Label_rectangle}->Layout['dx']);
+              self::$avery_formats[$label]['dy'] = self::unit_conv((string) $Template->{$Label_rectangle}->Layout['dy']);
+              self::$avery_formats[$label]['margin'] = self::unit_conv((string) $Template->{$Markup_margin}['size']);
+          }
+        }         
+      }
+    }
+  }                        
+
+  /**
+  * @brief Store the selected label data for future use
+  *
+  * @param $format Label format.
+  *
+  * @return No return value
+  */
+  function store_label_data($format)
+  {
+    variable_set('format',$format);
+    variable_set('template',self::$avery_formats[$format]);
+    return;
+  }
+
+  /**
+  * @brief Retrieve the selected label data and populate the 
+  *        appropriate array element
+  *
+  * @param none
+  *
+  * @return the label type
+  */
+  function fetch_label_data()
+  {
+    $format = variable_get('format','');
+    self::$avery_formats[$format] = variable_get('template','');
+    return ($format);
+  }
 
   /**
   * @brief Constructor, intializing PDF and setting label format
@@ -128,6 +140,9 @@ class tcpdf_label extends TCPDF {
   * @return No return value
   */
   function __construct($format = '5160') {
+
+//  $format = fetch_label_data ();
+
     if (is_array($format)) {
       $this->label_format = $format;
     }
@@ -141,7 +156,7 @@ class tcpdf_label extends TCPDF {
       }
     }
 
-    parent::__construct('P', 'mm', $this->label_format['paper-size']);
+    parent::__construct('P','mm', $this->label_format['paper-size']);
 
     // We (try to) handle margins internally, so disable TCPDF margins.
     $this->setMargins(0, 0);
@@ -160,19 +175,16 @@ class tcpdf_label extends TCPDF {
   */
   function addLabel($contents, $is_html = true) {
     // Compute writing position
-    $x_space_factor =
-      $this->label_format['width'] + $this->label_format['SpaceX'];
-    $page_x = $this->label_format['marginLeft']
-      + ($this->coord_x * $x_space_factor) + $this->label_format['padding'];
 
-    $y_space_factor =
-      $this->label_format['height'] + $this->label_format['SpaceY'];
-    $page_y = $this->label_format['marginTop']
-      + ($this->coord_y * $y_space_factor) + $this->label_format['padding'];
+    $page_x = $this->label_format['x0']
+      + ($this->coord_x * $this->label_format['dx']);
+
+    $page_y = $this->label_format['y0']
+      + ($this->coord_y * $this->label_format['dy']);
 
     // Compute cell size
-    $cell_width = $this->label_format['width'] - $this->label_format['padding'];
-    $cell_height = $this->label_format['height'] - $this->label_format['padding'];
+    $cell_width = $this->label_format['width'] - ($this->label_format['margin'] * 2);
+    $cell_height = $this->label_format['height'] - ($this->label_format['margin'] * 2);
 
     // Add text to PDF
     // TODO: enforce proper cell height somehow. Currently these writes
@@ -187,10 +199,10 @@ class tcpdf_label extends TCPDF {
 
     // Move internal coordinates, adding a page if necessary
     $this->coord_x++;
-    if ($this->coord_x == $this->label_format['NX']) {
+    if ($this->coord_x == $this->label_format['nx']) {
       $this->coord_x = 0;
       $this->coord_y++;
-      if ($this->coord_y == $this->label_format['NY']) {
+      if ($this->coord_y == $this->label_format['ny']) {
         // End of page
         $this->coord_y = 0;
         $this->addPage();
@@ -207,7 +219,7 @@ class tcpdf_label extends TCPDF {
   static function getAveryFormatOptions() {
     $options = array();
     foreach (self::$avery_formats as $key => $format) {
-      $options[$key] = t('Avery @key', array('@key' => $key));
+      $options[$key] = t('@key', array('@key' => $format['brand'] . ' ' . $key));
     }
     return $options;
   }
