diff --git a/js/webform_registration.js b/js/webform_registration.js
deleted file mode 100644
index 3089378..0000000
--- a/js/webform_registration.js
+++ /dev/null
@@ -1,6 +0,0 @@
-/* 
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-
diff --git a/page-registration.tpl.php b/page-registration.tpl.php
deleted file mode 100644
index 51051ba..0000000
--- a/page-registration.tpl.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
- * @file
- * Template file for displaying registration with reduced regions and no sidebars.
- */
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
-  <head>
-    <title><?php print $head_title ?></title>
-    <?php print $head ?>
-    <?php print $styles ?>
-    <?php print $scripts ?>
-    <!--[if lt IE 7]>
-    <?php print theme('get_ie_styles'); ?>
-    <![endif]-->
-  </head>
-  <body>
-    <!-- Special Page Template: page-registration.tpl.php -->
-    <!-- Layout -->
-    <div id="wrapper" class="sweepstakes">
-      <div id="container" class="clear-block">
-        <div id="page">
-
-          <?php if ($header): ?>
-            <div id="header-blocks" class="region region-header">
-              <?php print $header; ?>
-            </div> <!-- /#header-blocks -->
-          <?php endif; ?>
-
-          <?php
-          // @ToDo: Track what is removing the $messages variable.
-          print $temp_messages;
-          ?>
-
-          <?php if ($page == 0): ?>
-            <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
-          <?php endif; ?>
-          <div id="tabs">
-            <?php if ($tabs): print '<ul class="tabs primary">' . $tabs . '</ul>';
-            endif; ?>
-          </div>
-          <?php if ($tabs2): print '<ul class="tabs secondary">' . $tabs2 . '</ul>';
-          endif; ?>
-
-          <?php print $content_top; ?>
-<?php print $content ?>
-<?php print $content_bottom; ?>
-
-          <div class="clear-block clear">
-            <div class="meta">
-              <?php if ($taxonomy): ?>
-                <div class="terms"><?php print $terms ?></div>
-            <?php endif; ?>
-            </div>
-            <?php if ($links): ?>
-              <div class="links"><?php print $links; ?></div>
-<?php endif; ?>
-          </div>
-          <div class="clear-block clear"></div>
-        </div>
-      </div> <!-- close container -->
-    </div> <!-- close wrapper -->
-<?php print $closure ?>
-  </body>
-</html>
\ No newline at end of file
diff --git a/webform_registration.admin.inc b/webform_registration.admin.inc
old mode 100644
new mode 100755
index 0bc9caa..611e456
--- a/webform_registration.admin.inc
+++ b/webform_registration.admin.inc
@@ -1,20 +1,281 @@
 <?php
-
 /**
  * @file
- * Webform Registration Admin Include
+ * Webform Registration Include File.
  *
- * This file holds all the admin and non-user facing functionality.
+ * This file holds all the webform administration functionality
  */
 
+function webform_registration_settings_form($form, $form_state, $node) {
+
+  $components = $node->webform['components'];
+
+  if (empty($components)) {
+    $form['enabled']['#value'] = FALSE;
+    $form['enabled']['#disabled'] = TRUE;
+    $form['instructions'] = array(
+      '#type' => 'item',
+      '#title' => 'No available components',
+      '#description' => filter_xss(t('You must first !add_components. Then you can enable registration via this webform', array('!add_components' => l(t('Add  Components'), 'node/' . $node->nid . '/webform')))),
+    );
+    return $form;
+  }
+
+  $form_settings = $node->webform_registration;
+
+  $form['node'] = array(
+    '#type' => 'value',
+    '#default_value' => $node,
+  );
+
+  $form['webform_registration'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => TRUE,
+    '#tree' => TRUE,
+    '#title' => t('Registration Settings'),
+  );
+
+  $form['webform_registration']['nid'] = array(
+    '#type' => 'value',
+    '#default_value' => $node->nid,
+  );
+
+  $form['webform_registration']['enabled'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Allow users to register using this webform'),
+    '#default_value' => ($form_settings['enabled'] ? TRUE : FALSE),
+  );
+
+  // We do have components in this form, so let's process them into select options.
+  $options = array();
+  $fieldset = array(); // Holds form_key references to map pid to fieldset cids.
+  $auto = array('<auto>' => t('Generate field automatically'));
+  $none = array('<none>' => t('Omit field'));
+
+  foreach ($components as $component) {
+    // Available options are nid, cid, form_key, name, type, value, extra,
+    // mandatory, email, pid, weight, page_num
+    if ($component['type'] == 'fieldset') {
+      $fieldset[$component['cid']] = array('name' => $component['name'], 'form_key' => $component['form_key']);
+      $options[$component['name']] = array();
+    }
+    elseif ($component['pid'] != 0) {
+      $options[$fieldset[$component['pid']]['name']][$fieldset[$component['pid']]['form_key'] . '][' . $component['form_key']] = $component['name'];
+    }
+    else {
+      $options[$component['form_key']] = $component['name'];
+    }
+  }
+
+  $form['webform_registration']['name'] = array(
+    '#type' => 'select',
+    '#title' => t('Username field'),
+    '#description' => t('Select the field on this webform that will be used
+      for the username.'),
+    '#default_value' => $form_settings['name'],
+    '#options' => $options,
+    // @ToDo: Optionally implement automatic username generation.
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+  $form['webform_registration']['pass'] = array(
+    '#type' => 'select',
+    '#title' => t('Password field'),
+    '#description' => t('Select the field on this webform that will be used
+      for the user\'s password. Select &lt;auto&gt; to have Drupal generate a
+      random password. This field will be altered in the webform to hide the text entered where applicable.'),
+    '#default_value' => $form_settings['pass'],
+    '#options' => $auto + $options,
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+  $form['webform_registration']['pass_confirm'] = array(
+    '#type' => 'select',
+    '#title' => t('Password Confirmation field'),
+    '#default_value' => $form_settings['pass_confirm'],
+    '#options' => $none + $options,
+    '#description' => t('Selecting the same field selected above renders a second verification only dummy field. Select &lt;none&gt; to show only one email field.'),
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+  $form['webform_registration']['mail'] = array(
+    '#type' => 'select',
+    '#title' => t('Email Address field'),
+    '#default_value' => $form_settings['mail'],
+    '#options' => $options,
+    '#description' => t('Select the field on this webform that will be used for the user\'s email.'),
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+  $form['webform_registration']['mail_confirm'] = array(
+    '#type' => 'select',
+    '#title' => t('Email Confirmation field'),
+    '#default_value' => $form_settings['mail_confirm'],
+    '#options' => $none + $options,
+    '#description' => t('Selecting the same field selected above renders a second verification only dummy field. Select &lt;none&gt; to show only one email field.'),
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+
+  // Opt in.
+  $form['webform_registration']['opt_in'] = array(
+    '#type' => 'select',
+    '#title' => t('Opt In field'),
+    '#default_value' => $form_settings['opt_in'],
+    '#options' => $none + $options,
+    '#description' => t('Select the field on this webform that will be used to indicate that user opts in for registration. Select &lt;none&gt; to register all users.'),
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+  $form['webform_registration']['opt_in_value'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Opt In value'),
+    '#default_value' => $form_settings['opt_in_value'],
+    '#description' => t('Specify the value for Opt In field where user opts in for registration.'),
+    '#required' => FALSE,
+    '#maxlength' => 255,
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+
+  // Show list of user roles.
+  $roles = user_roles(TRUE);
+  $form['webform_registration']['roles'] = array(
+    '#type' => 'fieldset',
+    '#description' => t('Select the roles that users should be assigned to.'),
+    '#title' => t('User roles'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+    '#tree' => TRUE,
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+  foreach ($roles as $rid => $role) {
+    $form['webform_registration']['roles'][$rid] = array(
+      '#type' => 'checkbox',
+      '#title' => check_plain($role),
+      '#default_value' => (isset($form_settings['roles'][$rid]) ? TRUE : FALSE),
+      '#states' => array(
+        'invisible' => array(
+         'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+        ),
+      ),
+    );
+    // They're always authenticated users.
+    if ($rid == 2) {
+      $form['webform_registration']['roles'][$rid]['#default_value'] = TRUE;
+      $form['webform_registration']['roles'][$rid]['#disabled'] = TRUE;
+    }
+  }
+
+  $form['webform_registration']['theme_override'] = array(
+    '#type' => 'select',
+    '#title' => t('Override Page Template'),
+    '#default_value' => $form_settings['theme_override'],
+    '#options' => array(FALSE => t('Disabled'), TRUE => t('Enabled')),
+    '#description' => t('Select %enabled to use page-registration.tpl.php instead of page.tpl.php', array('%enabled' => t('Enabled'))),
+    '#states' => array(
+      'invisible' => array(
+       'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+      ),
+    ),
+  );
+
+  $user_field_info_instances = field_info_instances('user', 'user');
+  if (!empty($user_field_info_instances)) {
+    $form['webform_registration']['account_fields'] = array(
+      '#type' => 'fieldset',
+      '#collapsible' => TRUE,
+      '#tree' => TRUE,
+      '#title' => t('Account Fields'),
+       '#states' => array(
+          'invisible' => array(
+           'input[name="webform_registration[enabled]"]' => array('checked' => FALSE),
+          ),
+        ),
+    );
+    //Iterate around instances of user field
+    foreach ($user_field_info_instances as $field_name => $instance) {
+      $form['webform_registration']['account_fields'][$instance['field_name']] = array(
+        '#type' => 'select',
+        '#title' => check_plain($instance['label']),
+        '#description' => t('Select the field on this webform that will be used
+          for @field_name.', array("@field_name" => $instance['label'])),
+        '#default_value' => (isset($form_settings['account_fields'][$instance['field_name']]) ? $form_settings['account_fields'][$instance['field_name']] : ''),
+        '#options' => $none + $options,
+      );
+    }
+  }
+
+  $form['actions'] = array('#type' => 'actions');
+  $form['actions']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+  );
+
+  return $form;
+}
+
 /**
- * Implementation of hook_admin().
+ * Submit handler for webform_registration_settings_form
  */
-function webform_registration_admin() {
-  $form = array();
-  $form['placeholder'] = array(
-    '#type' => 'item',
-    '#value' => t('This is a placeholder for module wide settings to come'),
-  );
-  return system_settings_form($form);
+function webform_registration_settings_form_submit($form, &$form_state) {
+  $form_values = $form_state['values']['webform_registration'];
+  if (isset($form_values['account_fields'])) {
+    $form_values['account_fields'] = serialize($form_values['account_fields']);
+  }
+  // Store only required roles.
+  foreach ($form_values['roles'] as $rid => $selected) {
+    if (!$selected) {
+      unset($form_values['roles'][$rid]);
+    }
+  }
+  $form_values['roles'] = serialize($form_values['roles']);
+
+  //Check for existing record
+  $result = db_query("SELECT * FROM {webform_registration} WHERE nid = :nid", array(":nid" => $form_state['values']['node']->nid));
+  if ($result->rowCount() < 1) {
+    $result = drupal_write_record('webform_registration', $form_values);
+  }
+  else {
+    $result = drupal_write_record('webform_registration', $form_values, 'nid');
+  }
+  drupal_set_message(t('The registration settings have been updated.'));
+  return $result;
+}
+
+/**
+ * Validation handler for webform_registration_settings_form
+ */
+function webform_registration_settings_form_validate($form, &$form_state) {
+  $form_values = $form_state['values']['webform_registration'];
+
+  if ($form_values['enabled'] && ($form_values['opt_in'] != '<none>' && $form_values['opt_in_value'] == '')) {
+    form_set_error('webform_registration][opt_in_value', t('Opt In value is required'));
+  }
+
 }
diff --git a/webform_registration.inc b/webform_registration.inc
old mode 100644
new mode 100755
index 4664366..ca7714a
--- a/webform_registration.inc
+++ b/webform_registration.inc
@@ -8,108 +8,81 @@
  */
 
 /**
- * Extends hook_form_alter() functionality.
+ * Implements hook_form_alter().
  * Alters instances of registration enabled webforms.
  */
 function webform_registration_inc_form_alter(&$form, &$form_state, $form_id) {
   global $user;
 
-  $nid = $form['details']['nid']['#value'];
-  $settings = _webform_registration_get_settings($nid);
+  //Set user object
+  $form['#user'] = $user;
+
+  //Load the webform settings
+  $settings = $form['#node']->webform_registration;
+
   if (!$settings['enabled']) {
     return;
   }
 
-  $haystack = & $form['submitted'];
+  $haystack = &$form['submitted'];
   $fields = _webform_registration_get_fields($haystack, $settings);
 
   // Username field handling.
-  if (empty($fields['name']['field'])) {
-    drupal_set_message(t('Field %field not found', array('%field' => $settings['name'])), 'error');
+  if (isset($fields['name']['field'])) {
+    $fields['name']['field']['#required'] = TRUE;
   }
 
   // Password field handling.
   if ($settings['pass'] != '<auto>') {
     $fields['pass']['field']['#type'] = 'password';
+    $fields['pass']['field']['#required'] = TRUE;
   }
 
-  // Password confirmation handling
-  if ($settings['pass_confirm'] == '<none>') {
-    // We just don't show a confirmation field.
-  }
-  elseif ($settings['pass_confirm'] == $settings['pass']) {
-    // If they picked the same field for confirmation. We clone the pass field
-    $fields['pass']['field']['#type'] = 'password';
-    // Now we clone the pass field.
-    $fields['pass_confirm']['field'] = $fields['pass']['field'];
-    $fields['pass_confirm']['field']['#title'] = t('Password Confirmation');
-    $fields['pass_confirm']['field']['#description'] = t('Please type your password again.');
-    //$haystack[$settings['pass_confirm'] . '_confirm'] = $fields['pass_confirm']['field'];
-  }
-  elseif ($fields['pass_confirm']['field']['#type'] == 'textfield') {
+  // Password confirmation field handling
+  if ($settings['pass_confirm'] != '<none>') {
     $fields['pass_confirm']['field']['#type'] = 'password';
-    if (empty($fields['pass_confirm']['field']['#description'])) {
-      $fields['pass_confirm']['field']['#description'] = t('Please type your password again.');
-    }
   }
 
   // Email field handling
   if (isset($fields['mail']['field'])) {
     $fields['mail']['field']['#required'] = TRUE;
   }
-  else {
-    drupal_set_message(t('Field %field not found', array('%field' => $settings['mail'])), 'error');
-  }
 
-  // Email confirmation field handling
-  if ($settings['mail_confirm'] == '<none>') {
-    // We just don't show a confirmation field.
-  }
-  elseif ($settings['mail_confirm'] == $settings['mail']) {
-    // If they picked the same field for confirmation. We clone the mail field
-    $fields['mail_confirm']['field'] = $fields['mail']['field'];
-    $fields['mail_confirm']['field']['#title'] = t('Email Confirmation');
-    $fields['mail_confirm']['field']['#description'] = t('Please type your email again.');
-  }
-  else {
-    // They specified a different field for mail confirmation.
-    // @ToDo: Implement this usecase.
-  }
-  // @ToDo: Optionally. Implement javascript strength notification.
   // The user is logged in. QUICK! HIDE!
   if (user_is_logged_in()) {
     // Hide everything but populate the fields in case webform needs them for
-    // something, e.g. Connecting with a CRM or such.
+    // something, e.g. Connecting with a CRM or such
+    //Load User Data
+    $user_data = user_load($user->uid);
+
+    if (is_array($settings['account_fields'])) {
+      foreach ($settings['account_fields'] as $account_field => $field) {
+        $fields[$account_field]['field']['#attributes'] = array('readonly' => 'readonly');
+        $fields[$account_field]['field']['#value'] = $user_data->{$account_field}['und'][0]['value'];
+      }
+    }
 
-    $fields['name']['field']['#type'] = 'value';
+    $fields['name']['field']['#attributes'] = array('readonly' => 'readonly');
     $fields['name']['field']['#value'] = $user->name;
 
-    // We are not populating the password.
     $fields['pass']['field']['#type'] = 'value';
     $fields['pass']['field']['#value'] = '';
 
     $fields['pass_confirm']['field']['#type'] = 'value';
     $fields['pass_confirm']['field']['#value'] = '';
-    $fields['pass_confirm']['field']['#required'] = FALSE;
 
     $fields['mail']['field']['#attributes'] = array('readonly' => 'readonly');
     $fields['mail']['field']['#value'] = $user->mail;
 
-    $fields['mail_confirm']['field']['#type'] = 'value';
+    $fields['mail_confirm']['field']['#attributes'] = array('readonly' => 'readonly');
     $fields['mail_confirm']['field']['#value'] = $user->mail;
-    $fields['mail_confirm']['field']['#required'] = FALSE;
-
-    // @ToDo: Manage hiding fieldsets when all the fields are gone.
-    // $form['#submit'][]    = 'webform_registration_submit_login_only';
-    // $form['#validate'][]  = 'webform_registration_validate_login_only';
+    $form['#submit'][] = 'webform_registration_upgrade_submit';
   }
   else {
     $form['#validate'][] = 'webform_registration_validate';
     $form['#submit'][] = 'webform_registration_submit';
   }
   _webform_registration_set_fields($haystack, $fields);
-
-  drupal_add_js(array('webform_registration' => $settings), 'setting');
 }
 
 /**
@@ -117,8 +90,9 @@ function webform_registration_inc_form_alter(&$form, &$form_state, $form_id) {
  */
 function webform_registration_validate($form, &$form_state) {
 
-  $nid = $form['details']['nid']['#value'];
-  $settings = _webform_registration_get_settings($nid);
+  //Load the webform settings
+  $settings = $form['#node']->webform_registration;
+  $account = $form['#user'];
 
   if (isset($form_state['values']['submitted'])) {
     $haystack = &$form_state['values']['submitted'];
@@ -126,70 +100,71 @@ function webform_registration_validate($form, &$form_state) {
 
   $fields = _webform_registration_get_fields($haystack, $settings);
 
-  // If webform_registration is enabled for this form
-  if ($fields['enabled']) {
-    $user_exists = _webform_registration_user_exists($fields);
-    // ... and user exists
-    if ($user_exists['match'] === TRUE) {
-      // Password
-      if (empty($fields['pass']['value'])) {
-        form_set_error($fields['pass']['key'], t('Your password field can\'t be empty when logging in'));
-        return;
-      }
-      $login_validates = user_load(array(
-        'name' => $user_exists['name'],
-        'uid' => $user_exists['uid'],
-        'pass' => $fields['pass']['value'],
-        ));
-      if (!$login_validates) {
-        form_set_error($fields['pass']['key'], t('Your password and email don\'t match.'));
-        return;
-      }
+  // Validate new or changing username.
+  if (isset($fields['name']['value'])) {
+    if ($error = user_validate_name($fields['name']['value'])) {
+      form_set_error($fields['name']['key'], $error);
+    }
+    elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('name', db_like($fields['name']['value']), 'LIKE')->range(0, 1)->execute()->fetchField()) {
+      form_set_error($fields['name']['key'], t('The name %name is already taken.', array('%name' => $fields['name']['value'])));
+    }
+  }
+
+  // Validate the e-mail address, and check if it is taken by an existing user.
+  if ($error = user_validate_mail($fields['mail']['value'])) {
+    form_set_error($fields['mail']['key'], $error);
+  }
+  elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('mail', db_like($fields['mail']['value']), 'LIKE')->range(0, 1)->execute()->fetchField()) {
+    // Format error message dependent on whether the user is logged in or not.
+    if (user_is_logged_in()) {
+      form_set_error($fields['mail']['key'], t('The e-mail address %email is already taken.', array('%email' => $fields['mail']['value'])));
     }
     else {
-      // Username
-      if ($settings['user'] != '<none>' && empty($fields['user']['value'])) {
-        form_set_error($fields['user']['key'], t('Username field is required'));
-        return;
-      }
-      // Password
-      if (empty($fields['pass']['value'])) {
-        form_set_error($fields['pass']['key'], t('Your password field can\t be empty when loggin in'));
-        return;
-      }
-      // Password Confirmation
-      if ($settings['pass_confirm'] != '<none>' && $fields['pass']['value'] != $fields['pass_confirm']['value']) {
-        form_set_error($fields['pass_confirm']['key'], t('Your password and confirmation values do not match'));
-        return;
-      }
-      // Email Confirmation
-      if ($settings['mail_confirm'] != '<none>' && $fields['mail']['value'] != $fields['mail_confirm']['value']) {
-        form_set_error($fields['mail_confirm']['key'], t('Your email and confirmation addresses do not match'));
-        return;
-      }
+      form_set_error($fields['mail']['key'], t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $fields['mail']['value'], '@password' => url('user/password'))));
+    }
+  }
 
-      if (_webform_registration_user_exists($fields, TRUE)) {
-        form_set_error($fields['user']['key'], t('That username already exist'));
-        return;
-      }
+  // Email Confirmation
+  if ($settings['mail_confirm'] != '<none>' && $fields['mail']['value'] != $fields['mail_confirm']['value']) {
+    form_set_error($fields['mail_confirm']['key'], t('Your email and confirmation addresses do not match'));
+    return;
+  }
+
+  // Password Confirmation
+  if ($settings['pass_confirm'] != '<none>' && $fields['pass']['value'] != $fields['pass_confirm']['value']) {
+    form_set_error($fields['pass_confirm']['key'], t('Your password and confirmation values do not match'));
+    return;
+  }
 
-      // Username Validation
-      _webform_registration_map_registration_fields($form_state, $fields, $settings);
-      user_register_validate($form, $form_state);
+
+}
+
+/**
+ * Webform Registration Submit Handler - existing user
+ */
+function webform_registration_upgrade_submit($form, &$form_state) {
+  //Load the webform settings
+  $settings = $form['#node']->webform_registration;
+
+  global $user;
+  $account = user_load($user->uid);
+  $roles = user_roles(TRUE);
+  $all_roles = $account->roles;
+  if (isset($settings['roles']) && is_array($settings['roles'])) {
+    foreach ($settings['roles'] as $rid => $value) {
+      $all_roles[$rid] = $roles[$rid];
     }
   }
+  user_save($account, array('roles' => $all_roles));
 }
 
 /**
- * Webform Registration Submit Handler.
+ * Webform Registration Submit Handler - new user
  */
 function webform_registration_submit($form, &$form_state) {
-  $nid = $form['details']['nid']['#value'];
-  $settings = _webform_registration_get_settings($nid);
 
-  if (!$settings['enabled'] || user_is_logged_in()) {
-    return;
-  }
+  //Load the webform settings
+  $settings = $form['#node']->webform_registration;
 
   if (isset($form_state['values']['submitted_tree'])) {
     $haystack = &$form_state['values']['submitted_tree'];
@@ -198,80 +173,44 @@ function webform_registration_submit($form, &$form_state) {
   // Retrieve the values and/or form references
   $fields = _webform_registration_get_fields($haystack, $settings);
 
-  // Do we need to register or login the user?
-  $user_exists = _webform_registration_user_exists($fields);
-
-  if ($user_exists['match'] === TRUE) {
-    watchdog('webform_registration', 'Webform Registration: Login Triggered. %userid', array('%userid' => $user_exists['uid']));
-    $form_state['values']['name'] = $fields['name']['value'] = $user_exists['name'];
-
-    $user_form = _webform_registration_map_registration_fields($form_state, $fields);
-    $user = user_authenticate($user_form['values']);
+  // Has user has opted out of registration?
+  if ($settings['opt_in'] !== '<none>' && $settings['opt_in_value'] != $haystack[$settings['opt_in']]) {
+    return;
   }
-  else {
-    watchdog('webform_registration', 'Webform Registration: Registration Triggered');
-    $redirect = array_shift($form_state['redirect']);
 
-    $user_form = _webform_registration_map_registration_fields($form_state, $fields);
-    $user_form['values']['notify'] = FALSE;
+  watchdog('webform_registration', 'Webform Registration: Registration Triggered');
 
-    user_register_submit($form, $user_form);
+  $user_register_info = array(
+    'values' => array(
+      'mail' => $fields['mail']['value'],
+      'name' => $fields['name']['value'],
+      'notify' => 0,
+      'status' => 1,
+      'pass' => ($fields['pass']['key'] != '<auto>' ? $fields['pass']['value'] : user_password()),
+      'roles' => $settings['roles'],
+    ),
+    'buttons' => array(),
+  );
 
-    $form_state['redirect'] = $redirect;
+  //Add use field instances
+  $user_field_info_instances = field_info_instances('user', 'user');
+  foreach ($user_field_info_instances as $field_name => $instance) {
+    if (!in_array($fields[$field_name]['value'], _webform_registration_get_special_needles())) {
+      $user_register_info['values'][$field_name]['und'][0]['value'] = $fields[$field_name]['value'];
+    }
   }
+  user_register_submit($form, $user_register_info);
 
-  // Content Profile Tie-in
-  if (module_exists('content_profile')) {
-    webform_registration_profile($form_state);
-  }
+  // Update the main submission info.
+  db_update('webform_submissions')
+    ->fields(array(
+      'uid' => $user_register_info['values']['uid'],
+    ))
+    ->condition('sid', $form_state['values']['details']['sid'])
+    ->execute();
 }
 
-function webform_registration_profile(&$form_state) {
-  if (user_is_anonymous()) {
-    return FALSE;
-  }
-
-  global $user;
-  $content_types = content_profile_get_types('names');
-
-  foreach ($content_types as $type => $name) {
-    $node = new stdClass();
-    $node->type = $type;
-    $node->uid = $user->uid;
-    $node->title = $user->name;
-
-    if (content_profile_profile_exists($node, $user->uid)) {
-      $node = node_load((array) $node);
-    }
-    else {
-      node_save($node);
-    }
-
-    foreach ($node as $key => $value) {
-      if (strstr($key, 'field')) {
-        $needle = str_replace('field_', '', $key);
-        if ($found = _find_in_array($needle, $form_state['values']['submitted_tree'])) {
-          $node->{$key}[0]['value'] = $found;
-        }
-      }
-    }
-    node_save($node);
-  }
-}
 
-/**
- * Function that takes the values for the form, finds the email, and checks if
- * the user already exists.
- */
-function _webform_registration_user_exists($fields, $check_both = FALSE) {
-  $mail = webform_registration_email_exists($fields['mail']['value']);
-  $ret = $mail['match'];
-  if ($check_both == TRUE) {
-    $uname = webform_registration_user_exists($fields['user']['value']);
-    $ret = $uname['match'] || $ret;
-  }
-  return $ret;
-}
 
 /*
  * Recursively tries to find a value in nested arrays
@@ -292,56 +231,13 @@ function _find_in_array($needle, &$array) {
 }
 
 /**
- * Checks if a given email exists in the name or mail columns of the users table.
- */
-function webform_registration_email_exists($string) {
-  $match = array('match' => FALSE);
-  if (!empty($string)) {
-    $result = db_query("SELECT uid, name
-    FROM {users}
-    WHERE LOWER(mail) = LOWER('%s') LIMIT 1;
-    ", $string);
-    while ($user = db_fetch_array($result)) {
-      $match = array(
-        'match' => TRUE,
-        'uid' => $user['uid'],
-        'name' => $user['name'],
-      );
-    }
-  }
-  return $match;
-}
-
-/**
- * Checks if a given username exists in the name or mail columns of the users table.
- */
-function webform_registration_user_exists($string) {
-  $match = array('match' => FALSE);
-  if (!empty($string)) {
-    $result = db_query("SELECT uid, name
-    FROM {users}
-    WHERE LOWER(name) = LOWER('%s') LIMIT 1;
-    ", $string);
-    while ($user = db_fetch_array($result)) {
-      $match = array(
-        'match' => TRUE,
-        'uid' => $user['uid'],
-        'name' => $user['name'],
-      );
-    }
-  }
-  return $match;
-}
-
-/**
  * Helper function that retrieves the values to be used with the user
  * registration. This is front-end and end-user.
  */
 function _webform_registration_get_fields(&$haystack, $settings) {
-  if (empty($settings['enabled'])) {
-    return $settings;
+  if (is_array($settings['account_fields'])) {
+    $settings = array_merge($settings, $settings['account_fields']);
   }
-
   $fields = array();
 
   // Retrieve a list of the keys allowed to be fetched recursively
@@ -397,7 +293,7 @@ function _webform_registration_get_form_field($needle, &$haystack, $value = NULL
   $ret = array(
     'key' => $needle,
     'field' => (is_array($field) ? $field : NULL),
-    'value' => (is_array($field) ? $field['#value'] : $field),
+    'value' => (is_array($field) ? (isset($field['#value']) ? $field['#value'] : NULL) : $field),
   );
 
   return $ret;
@@ -411,34 +307,6 @@ function _webform_registration_set_form_field($needle, &$haystack, $value) {
 }
 
 /**
- * Maps user entered form values into the $form_state array where user module expects them to be.
- */
-function _webform_registration_map_registration_fields(&$form_state, $fields) {
-  $user_form = array();
-
-  // Prepare fields for validation and map them out into the values
-  // These are the keys that the user module expects for validation and insertion.
-  if (!empty($fields['mail']['value'])) {
-    $form_state['values']['mail'] = $fields['mail']['value'];
-  }
-  if ($fields['name']['key'] != '<none>') {
-    $form_state['values']['name'] = $fields['name']['value'];
-  }
-  else {
-    $form_state['values']['name'] = $fields['mail']['value'];
-  }
-
-  // If pass equals <auto> then just assign '' so that the user module can generate that for us.
-  $form_state['values']['pass'] = ($fields['pass']['key'] != '<auto>' ? $fields['pass']['value'] : '');
-
-  // User registrations frowns when it sees a uid key.
-  $registration = array_flip(array_keys(user_register()));
-  $user_form['values'] = array_intersect_key($form_state['values'], $registration);
-
-  return $user_form;
-}
-
-/**
  * Iterates over the $fields and assigns their values to the $haystack.
  */
 function _webform_registration_set_fields(&$haystack, &$fields) {
@@ -453,51 +321,21 @@ function _webform_registration_set_fields(&$haystack, &$fields) {
 }
 
 /**
- * Returns a specific portion of a needle path;
- */
-function _webform_registration_get_needle_part($needle, $part = 'all') {
-  $path = explode('][', $needle);
-  $depth = count($path);
-
-  // Translates $part into actual numeric values.
-  switch ($part) {
-    case 'first':
-      $part = 0;
-      break;
-    case 'last':
-      $part = $depth - 1;
-      break;
-    case 'next to last':
-      $part = $depth - 2;
-      break;
-    case 'all':
-    default:
-      // Not being a number will tell us to send the whole $path array.
-      $part = 'all';
-      break;
-  }
-
-  // $part must be numeric now.
-  if ($part === 'all') {
-    return $path;
-  }
-  else {
-    return $path[$part];
-  }
-}
-
-/**
  * Retrieves an array of only the fields a user can modify.
  * Useful for fetching from the registration webform.
  */
 function _webform_registration_get_valid_form_fields() {
-  return array(
+
+  $user_field_info_instances = field_info_instances('user', 'user');
+  $valid_form_fields = drupal_map_assoc(array(
     'name',
     'mail',
     'mail_confirm',
     'pass',
     'pass_confirm',
-  );
+  ));
+
+  return array_merge($valid_form_fields, array_keys($user_field_info_instances));
 }
 
 /**
@@ -509,4 +347,4 @@ function _webform_registration_get_special_needles() {
     '<none>',
     '<auto>',
   );
-}
\ No newline at end of file
+}
diff --git a/webform_registration.info b/webform_registration.info
old mode 100644
new mode 100755
index ef8f596..e07a014
--- a/webform_registration.info
+++ b/webform_registration.info
@@ -2,5 +2,6 @@ name = Webform Registration
 description = Allows Webform module to generate users.
 package = "Webform"
 dependencies[] = webform
-version = 6.x-1.0
-core = 6.x
\ No newline at end of file
+version = 7.x-2.0
+core = 7.x
+files[] = webform_registration.inc
\ No newline at end of file
diff --git a/webform_registration.install b/webform_registration.install
old mode 100644
new mode 100755
index d744802..96c4def
--- a/webform_registration.install
+++ b/webform_registration.install
@@ -5,7 +5,7 @@
  */
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function webform_registration_schema() {
   $schema = array();
@@ -58,6 +58,24 @@ function webform_registration_schema() {
         'not null' => TRUE,
         'default' => 0,
       ),
+      'account_fields' => array(
+        'description' => 'Serialized array of user fields containing their respective references to webform components',
+        'type' => 'text',
+      ),
+      'opt_in' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'description' => 'Source field indicating user opts in for automatic registration'
+      ),
+      'opt_in_value' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'description' => 'Source field value indicating opts in for automatic registration'
+      ),
+      'roles' => array(
+        'type' => 'text',
+        'description' => 'Serialized array of user roles to assign new user to'
+      ),
     ),
     'primary key' => array('nid'),
   );
@@ -65,19 +83,12 @@ function webform_registration_schema() {
 }
 
 /**
- * Implementation of hook_install().
+ * Add columns for opt-in and user roles.
  */
-function webform_registration_install() {
-  // db_query("UPDATE {system} SET weight = -1 WHERE name='webform_registration' AND type='module'");
-  drupal_install_schema('webform_registration');
-  drupal_set_message(t('Webform Registration module is now installed.'));
-  drupal_set_message(t('Don\'t forget to configure the !permissions for this module.', array('!permissions' => l('Permissions', 'admin/user/permissions', array('fragment' => 'module-webform_registration')))));
+function webform_registration_update_7101() {
+  if (!db_field_exists('webform_registration', 'opt_in')) {
+    db_add_field('webform_registration', 'opt_in', array('type' => 'varchar', 'length' => 255, 'description' => 'Source field indicating user opts in to automatic registration'));
+    db_add_field('webform_registration', 'opt_in_value', array('type' => 'varchar', 'length' => 255, 'description' => 'Source field value indicating opts in for automatic registration'));
+    db_add_field('webform_registration', 'roles', array('type' => 'text', 'description' => 'Serialized array of user roles to assign new user to'));
+  }
 }
-
-/**
- * Implementation of hook_uninstall().
- */
-function webform_registration_uninstall() {
-  // Drop tables.
-  drupal_uninstall_schema('webform_registration');
-}
\ No newline at end of file
diff --git a/webform_registration.module b/webform_registration.module
old mode 100644
new mode 100755
index a665455..42dd42b
--- a/webform_registration.module
+++ b/webform_registration.module
@@ -6,200 +6,30 @@
  *
  * Allows Webform module to generate users.
  */
-// User facing functions
-module_load_include('inc', 'webform_registration');
+
+// Load webform_registration.inc
+module_load_include('inc', 'webform_registration', 'webform_registration');
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function webform_registration_menu() {
   $items = array();
-  //  $items['admin/settings/webform_registration'] = array(
-  //    'title' => 'Webform Registration Settings',
-  //    'description' => 'Set module wide settings for webform registration',
-  //    'page callback' => 'drupal_get_form',
-  //    'page arguments' => array('webform_registration_admin'),
-  //    'access arguments' => array('access administration pages'),
-  //    'file' => 'webform_registration.admin.inc'
-  //  );
-  return $items;
-}
-
-/**
- * Implementation of hook_perm().
- */
-function webform_registration_perm() {
-  return array(
-    //'administer webform registration', // To be included when we have module-specific settings.
-    'enable webform registration',
-  );
-}
-
-/**
- * Implementation of hook_form_FORM_ID_alter().
- * Alters the webform_node_form. This is admin only, not user facing.
- */
-function webform_registration_form_webform_node_form_alter(&$form, &$form_state) {
-  if (!user_access('enable webform registration')) {
-    return;
-  }
-
-  $nid = (isset($form['nid']['#value']) ? $form['nid']['#value'] : NULL);
-  $form_settings = _webform_registration_get_settings($nid);
-
-  $form['webform_registration'] = array(
-    '#type' => 'fieldset',
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-    '#title' => t('Webform Registration Settings'),
-    '#weight' => -1,
-    '#tree' => TRUE,
-  );
-  $form['webform_registration']['nid'] = array(
-    '#type' => 'value',
-    '#default_value' => $form_settings['nid'],
-  );
-  $form['webform_registration']['enabled'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Allow users to register using this webform'),
-    '#default_value' => ($form_settings['enabled'] ? TRUE : FALSE),
-    '#description' => t('Fields selected below will become required when the webform is rendered'),
-  );
-
-  // Now let's see if we have components to draw from.
-  if (isset($form['webform']['components']['#value'])) {
-    // Legacy version
-    $components = $form['webform']['components']['#value'];
-  }
-  elseif (isset($form['#node']->webform) && !empty($form['#node']->webform['components'])) {
-    // Newer versions
-    $components = $form['#node']->webform['components'];
-  }
-
-  if (empty($components)) {
-    $form['webform_registration']['enabled']['#value'] = FALSE;
-    $form['webform_registration']['enabled']['#disabled'] = TRUE;
-    $form['webform_registration']['enabled']['#description'] = t('After adding components to this form any textfield, select, or hidden form element may be used to create users');
-
-    // Let's prepare some instructions for the users.
-    if ($nid) {
-      $str_instructions = t('You must first !add_components. Then you can enable Webform Registration for this webform', array('!add_components' => l('Add  Components', 'node/' . $nid . '/edit/components')));
-    }
-    else {
-      $str_instructions = t('You must save this webform and add components to it. Then you can enable Webform Registration for this webform');
-    }
-    $form['webform_registration']['instructions'] = array(
-      '#type' => 'item',
-      '#title' => 'No available components',
-      '#description' => $str_instructions,
-    );
-    return $form;
-  }
-
-  // We do have components in this form, so let's process them into select options.
-  $options = array();
-  $fieldset = array(); // Holds form_key references to map pid to fieldset cids.
-  $auto = array('<auto>' => 'Generate field automatically');
-  $none = array('<none>' => 'Omit field');
-
-  foreach ($components as $component) {
-    // Available options are nid, cid, form_key, name, type, value, extra,
-    // mandatory, email, pid, weight, page_num
-    if ($component['type'] == 'fieldset') {
-      $fieldset[$component['cid']] = array('name' => $component['name'], 'form_key' => $component['form_key']);
-      $options[$component['name']] = array();
-    }
-    elseif ($component['pid'] != 0) {
-      $options[$fieldset[$component['pid']]['name']][$fieldset[$component['pid']]['form_key'] . '][' . $component['form_key']] = $component['name'];
-    }
-    else {
-      $options[$component['form_key']] = $component['name'];
-    }
-  }
-
-  $form['webform_registration']['name'] = array(
-    '#type' => 'select',
-    '#title' => t('Username field'),
-    '#description' => t('Select the field on this webform that will be used
-      for the username.'),
-    '#default_value' => $form_settings['name'],
-    '#options' => $options,
-    // @ToDo: Optionally implement automatic username generation.
-  );
-  $form['webform_registration']['pass'] = array(
-    '#type' => 'select',
-    '#title' => t('Password field'),
-    '#description' => t('Select the field on this webform that will be used
-      for the user\'s password. Select &lt;auto&gt; to have Drupal generate a
-      random password. This field will be altered in the webform to hide the text entered where applicable.'),
-    '#default_value' => $form_settings['pass'],
-    '#options' => $auto + $options,
-  );
-  $form['webform_registration']['pass_confirm'] = array(
-    '#type' => 'select',
-    '#title' => t('Password Confirmation field'),
-    '#default_value' => $form_settings['pass_confirm'],
-    '#options' => $none + $options,
-    '#description' => t('Selecting the same field selected above renders a second verification only dummy field. Select &lt;none&gt; to show only one email field.'),
+  $items['node/%webform_menu/webform/registration'] = array(
+    'title' => 'Registration Settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('webform_registration_settings_form', 1),
+    'access callback' => 'node_access',
+    'access arguments' => array('update', 1),
+    'file' => 'webform_registration.admin.inc',
+    'weight' => 3,
+    'type' => MENU_LOCAL_TASK,
   );
-  $form['webform_registration']['mail'] = array(
-    '#type' => 'select',
-    '#title' => t('Email Address field'),
-    '#default_value' => $form_settings['mail'],
-    '#options' => $options,
-    '#description' => t('Select the field on this webform that will be used for the user\'s email.'),
-  );
-  $form['webform_registration']['mail_confirm'] = array(
-    '#type' => 'select',
-    '#title' => t('Email Confirmation field'),
-    '#default_value' => $form_settings['mail_confirm'],
-    '#options' => $none + $options,
-    '#description' => t('Selecting the same field selected above renders a second verification only dummy field. Select &lt;none&gt; to show only one email field.'),
-  );
-
-  $form['webform_registration']['theme_override'] = array(
-    '#type' => 'select',
-    '#title' => t('Override Page Template'),
-    '#default_value' => $form_settings['theme_override'],
-    '#options' => array(FALSE => t('Disabled'), TRUE => t('Enabled')),
-    '#description' => t('Select %enabled to use page-registration.tpl.php instead of page.tpl.php', array('%enabled' => t('Enabled'))),
-  );
-
-  // This values get processed using hook_nodeapi() so we don't need a submit or validate function.
-  $form['#validate'][] = 'webform_registration_edit_form_validate';
-  $form['buttons']['submit']['#submit'][] = 'webform_registration_edit_form_submit';
-}
-
-/**
- * Admin form validate handler
- */
-function webform_registration_edit_form_validate($form, &$form_state) {
-  // Get only the portion of the form that we care about.
-  $form_values = $form_state['values']['webform_registration'];
-}
-
-/**
- * Admin form submit handler
- * 
- * @param array $form
- * @param array $form_state
- * @return integer SAVED_NEW or SAVED_UPDATED 
- */
-function webform_registration_edit_form_submit($form, &$form_state) {
-  $nid = $form_state['nid'];
-  $existing_record = _webform_registration_get_settings($nid);
-  $form_values = $form_state['values']['webform_registration'];
-  if (!$existing_record['nid']) {
-    $result = drupal_write_record('webform_registration', $form_values);
-  }
-  else {
-    $result = drupal_write_record('webform_registration', $form_values, 'nid');
-  }
-  return $result;
+  return $items;
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
  */
 function webform_registration_form_alter(&$form, &$form_state, $form_id) {
   if (drupal_substr($form_id, 0, 19) == 'webform_client_form') {
@@ -208,81 +38,72 @@ function webform_registration_form_alter(&$form, &$form_state, $form_id) {
 }
 
 /**
- * Implementation of hook_nodeapi()/
+ * Implements hook_node_insert().
  */
-function webform_registration_nodeapi(&$node, $op, $a3, $a4) {
-  if ($node->type != 'webform') {
-    return; // If it's not a webform node, skip everything,
-  }
-
-  switch ($op) {
-    case 'insert' :
-      if (isset($node->webform_registration)
-        && $node->webform_registration['nid'] !== $node->nid) {
-        $form_values = $node->webform_registration;
-        $form_values['nid'] = $node->nid;
-        drupal_write_record('webform_registration', $form_values);
-      }
-      break;
-    case 'load':
-      $node->webform_registration = _webform_registration_get_settings($node->nid);
-      break;
+function webform_registration_node_insert($node) {
+  if ($node->type == 'webform' && isset($node->webform_registration)
+    && $node->webform_registration['nid'] !== $node->nid) {
+    $form_values = $node->webform_registration;
+    $form_values['nid'] = $node->nid;
+    $form_values['account_fields'] = serialize($form_values['account_fields']);
+    $form_values['roles'] = serialize($form_values['roles']);
+    drupal_write_record('webform_registration', $form_values);
   }
 }
 
 /**
- * Retrieves the settings to be used with a particular webform.
- * If $nid is not passed, default values are returned;
+ * Implements hook_node_load().
  */
-function _webform_registration_get_settings($nid = 0) {
-  // Set some defaults for returning when there is no row defined
-  $form_settings = array(
-    'nid' => $nid,
-    'uid' => 0,
-    'enabled' => FALSE,
-    'name' => 'name',
-    'mail' => 'mail',
-    'mail_confirm' => 'mail_confirm',
-    'pass' => 'pass',
-    'pass_confirm' => 'pass_confirm',
-    'theme_override' => 'theme_override',
-  );
-
-  if ($nid > 0) {
-    $sql = "SELECT nid, enabled, name, mail, mail_confirm, pass, pass_confirm,
-    theme_override
-    FROM {webform_registration}
-    WHERE nid = %d";
-
-    $result = db_query_range($sql, $nid, 0, 1);
-    while ($settings = db_fetch_array($result)) {
-      $form_settings = $settings;
+function webform_registration_node_load($nodes, $types) {
+  foreach ($nodes as $node) {
+    if ($node->type == 'webform') {
+      $node->webform_registration = array(
+        'nid' => $node->nid,
+        'uid' => 0,
+        'enabled' => FALSE,
+        'name' => 'name',
+        'mail' => 'mail',
+        'mail_confirm' => 'mail_confirm',
+        'pass' => 'pass',
+        'pass_confirm' => 'pass_confirm',
+        'theme_override' => 'theme_override',
+        'account_fields' => array(),
+        'opt_in' => '',
+        'opt_in_value' => '',
+        'roles' => array(),
+      );
+
+      $sql = "SELECT * FROM {webform_registration} WHERE nid = :nid";
+      $result = db_query($sql, array(':nid' => $node->nid));
+      while ($setting = $result->fetchAssoc()) {
+        $node->webform_registration = $setting;
+        $node->webform_registration['account_fields'] = unserialize($setting['account_fields']);
+        $node->webform_registration['roles'] = unserialize($setting['roles']);
+      }
     }
   }
-
-  return $form_settings;
 }
 
 /**
- * Implementation $modulename_preprocess_$hook().
+ * Implements $modulename_preprocess_$hook().
  */
 function webform_registration_preprocess_page(&$variables) {
-  $node = $variables['node'];
-  // Temp fix to error messages not being shown;
-  $variables['temp_messages'] = $variables['messages'];
-
-  if ($node->type == 'webform' && $node->webform_registration['theme_override']) {
-    // Add suggestions: a node specific and a generic page-registration.tpl.php
-    $variables['template_files'][] = 'page-registration';
-    $variables['template_files'][] = 'page-registration-' . $node->nid;
+  //If we are on a node page.
+  if (isset($variables['node'])) {
+    $node = $variables['node'];
+
+    if ($node->type == 'webform' && $node->webform_registration['theme_override']) {
+      // Add suggestions: a node specific and a generic page-registration.tpl.php
+      $variables['template_files'][] = 'page-registration';
+      $variables['template_files'][] = 'page-registration-' . $node->nid;
+    }
   }
 }
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function webform_registration_theme($existing, $type, $theme, $path) {
-  // N2S: $path == drupal_get_path($type, $theme);
   return array(
     'page' => array(
       'template' => 'page-registration',
@@ -294,21 +115,3 @@ function webform_registration_theme($existing, $type, $theme, $path) {
     ),
   );
 }
-
-/**
- * Implementation of hook_clone_node_alter().
- */
-function webform_registration_clone_node_alter(&$node, $original_node, $method) {
-  $node->webform_registration = _webform_registration_get_settings($original_node->nid);
-}
-
-/**
- * Boolean function that checks if a given $nid is allowed to register users.
- */
-function webform_registration_is_node_enabled($nid = NULL) {
-  if (is_numeric($nid) && $nid > 0) {
-    $settings = _webform_registration_get_settings($nid);
-    return $settings['enabled'];
-  }
-  return FALSE;
-}
\ No newline at end of file
