diff --git advpoll-display-binary-form.tpl.php advpoll-display-binary-form.tpl.php
new file mode 100644
index 0000000..b9b98ea
--- /dev/null
+++ advpoll-display-binary-form.tpl.php
@@ -0,0 +1,27 @@
+<?php
+// $Id$
+
+/**
+ * @file advpoll-display-binary-form.tpl.php
+ * Default theme implementation to show voting form for binary polls.
+ *
+ * $writein_choice - writein_choice element, if poll needs it.
+ * $form_id
+ * $form_submit
+ * $choice_list - choices in the poll.
+ */
+?>
+<div class="poll">
+  <div class="advpoll-available-choices">
+    <div class="choice-header"><?php print t('Choices') ?></div>
+    <div class="vote-choices">
+      <?php print $choice_list ?>
+    </div>
+    <?php if (isset($writein_choice)) { ?>
+    <div class="writein-choice"><?php print $writein_choice ?></div>
+    <?php } ?>
+  </div>
+  <?php print $form_submit ?>
+  <br clear="left" />
+  <?php if ($message) {?><p class="message"><?php print $message ?></p><?php } ?>
+</div>
diff --git advpoll-display-ranking-form.tpl.php advpoll-display-ranking-form.tpl.php
index b096eb7..a455848 100644
--- advpoll-display-ranking-form.tpl.php
+++ advpoll-display-ranking-form.tpl.php
@@ -12,29 +12,24 @@
  * $tabledrag_group_class
  */
 ?>
-<?php
-  // Add table JavaScript.
-  drupal_add_js(drupal_get_path('module', 'advpoll') .'/advpoll-vote.js');
-  drupal_add_tabledrag($form_id . '-table', 'order', 'self', 'advpoll-choice-order', NULL, NULL, FALSE);
-?>
 <div class="poll">
-<div class="advpoll-available-choices">
-<div class="choice-header"><?php print t('Choices') ?></div>
-<div class="vote-choices">
-<?php print $choice_list ?>
-</div>
-<?php if (isset($writein_choice)) { ?>
-<div class="writein-choice"><?php print $writein_choice ?></div>
-<?php } ?>
-</div>
-<!-- table-drag re-ordering if JavaScript is enabled. -->
-<div class="advpoll-drag-box">
-<div class="advpoll-vote-header"><?php print t('Your Vote') ?></div>
-<table cellspacing=0 id="<?php print $form_id ?>-table" class="advpoll-existing-choices-table">
-</table>
-<div class="vote-status"></div>
-</div>
-<?php print $form_submit ?>
-<br clear="left" />
-<?php if ($message) {?><p class="message"><?php print $message ?></p><?php } ?>
+  <div class="advpoll-available-choices">
+    <div class="choice-header"><?php print t('Choices') ?></div>
+    <div class="vote-choices">
+      <?php print $choice_list ?>
+    </div>
+    <?php if (isset($writein_choice)) { ?>
+    <div class="writein-choice"><?php print $writein_choice ?></div>
+    <?php } ?>
+  </div>
+  <!-- table-drag re-ordering if JavaScript is enabled. -->
+  <div class="advpoll-drag-box">
+    <div class="advpoll-vote-header"><?php print t('Your Vote') ?></div>
+    <table cellspacing=0 id="<?php print $form_id ?>-table" class="advpoll-existing-choices-table">
+    </table>
+    <div class="vote-status"></div>
+  </div>
+  <?php print $form_submit ?>
+  <br clear="left" />
+  <?php if ($message) {?><p class="message"><?php print $message ?></p><?php } ?>
 </div>
diff --git advpoll-vote.js advpoll-vote.js
index e63a585..b81c647 100644
--- advpoll-vote.js
+++ advpoll-vote.js
@@ -44,7 +44,6 @@ Drupal.behaviors.handleWriteins = function(context) {
       // No write-ins in this poll.
       return;
     }
-    var ranOnce = false;
     // Toggle display of the write-in text box for radios/checkboxes.
     $(".vote-choices input[type=radio], .vote-choices input[type=checkbox]", poll).click(function() {
       var isLast = $(this).val() == $(".vote-choices input[type=radio]:last, .vote-choices input[type=checkbox]:last", poll).val();
@@ -52,12 +51,6 @@ Drupal.behaviors.handleWriteins = function(context) {
       // The logic here is tricky but intentional.
       if (isLast || type == "radio") {
         var showChoice = isLast && (type == "radio" || $(this).attr("checked"));
-        if (!ranOnce && showChoice) {
-          // If this is our first time, clone the Drupal-added write-in element
-          // and add a new one next to the checkbox, then delete the old one.
-          $(".writein-choice input", poll).clone().addClass("writein-choice").insertAfter($(this).parent()).end().parent().parent().remove();
-          ranOnce = true;
-        }
         $(".writein-choice", poll).css("display", showChoice ? "inline" : "none");
         if (showChoice) {
           $(".writein-choice", poll)[0].focus();
@@ -71,12 +64,6 @@ Drupal.behaviors.handleWriteins = function(context) {
     // Toggle display of the write-in text box for select boxes.
     // Fire on change() rather than click(), for Safari compatibility.
     $(".vote-choices select:last", poll).change(function() {
-      if (!ranOnce) {
-        // If this is our first time, clone the Drupal-added write-in element
-        // and add a new one next to the checkbox, then delete the old one.
-        $(".writein-choice input", poll).clone().addClass("writein-choice").insertAfter($(this)).end().parent().parent().remove();
-        ranOnce = true;
-      }
       var showChoice = $(this).val() > 0;
       var alreadyVisible = $(".writein-choice", poll).css("display") == "inline";
       $(".writein-choice", poll).css("display", showChoice ? "inline" : "none");
@@ -165,7 +152,7 @@ Drupal.behaviors.rankingDragAndDrop = function(context) {
         else {
           // Hack to have tabledrag.js parse the new table rows.
           $existingChoicesTable.removeClass('dragtable-processed');
-          Drupal.attachBehaviors();
+          Drupal.attachBehaviors($existingChoicesTable);
         }
         $(".vote-status", mainForm).show().html(Drupal.t("Choices remaining: %choices", {"%choices" : maxChoices - currentChoices}));
         if (currentChoices > maxChoices) {
diff --git advpoll.module advpoll.module
index f0fc6fa..d6071b3 100644
--- advpoll.module
+++ advpoll.module
@@ -199,9 +199,6 @@ function advpoll_init() {
   // Load the mode include files.
   _advpoll_list_modes();
 
-  if (module_exists('jquery_ui')) {
-    jquery_ui_add(array('ui.draggable', 'ui.droppable', 'ui.sortable'));
-  }
 }
 
 /**
@@ -1661,6 +1658,13 @@ function advpoll_theme() {
         'form' => NULL,
       )
     ),
+    'advpoll_voting_binary_form' => array(
+      'template' => 'advpoll-display-binary-form',
+      'file' => 'modes/binary.inc',
+      'arguments' => array(
+        'form' => NULL,
+      )
+    ),    
   );
 }
 
diff --git modes/binary.inc modes/binary.inc
index 054d4d5..1edfc76 100644
--- modes/binary.inc
+++ modes/binary.inc
@@ -56,8 +56,6 @@ function advpoll_voting_binary_form(&$form_state, $node, $teaser, $page, $status
 
     $form['choice'] = array(
       '#options' => $list,
-      '#prefix' => '<div class="vote-choices">',
-      '#suffix' => '</div>',
       '#tree' => TRUE,
     );
 
@@ -77,8 +75,6 @@ function advpoll_voting_binary_form(&$form_state, $node, $teaser, $page, $status
   // Add write-in text field if write-ins are enabled and user has permission.
   if ($node->writeins && user_access('add write-ins')) {
     $form['writein_choice'] = array(
-      '#prefix' => '<div class="writein-choice">',
-      '#suffix' => '</div>',
       '#type' => 'textfield',
       '#title' => t('Write-in vote'),
       '#size' => 25,
@@ -303,18 +299,30 @@ function advpoll_voting_binary_form_validate($form, &$form_state) {
 }
 
 /**
- * Render the voting form.
+ * Process variables for advpoll-display-binary-form.tpl.php.
+ *
+ * The variables array contains the following arguments:
+ * - $form
+ *
+ * @see advpoll-display-binary-form.tpl.php
  */
-function theme_advpoll_voting_binary_form($form) {
-  $message = drupal_render($form['message']);
+function advpoll_preprocess_advpoll_voting_binary_form(&$variables) {
+  $form = &$variables['form'];
+  $variables['message'] = drupal_render($form['message']);
   
-  $output = "<div class=\"poll\">\n";
-  $output .= drupal_render($form);
-  if ($message) {
-    $output .= "<p class=\"message\">$message</p>\n";
+  // If write-ins are used on this form.
+  if (isset($form['writein_choice'])) {
+    $variables['writein_choice'] = drupal_render($form['writein_choice']);
   }
-  $output .= "</div>\n";
-  return $output;
+  $variables['form_id'] = $form['#id'];
+
+  // List of available choices in the poll.
+  $variables['choice_list'] = drupal_render($form['choice']);
+  // Take off the annoying colon & endlines that Drupal adds to each title.
+  $variables['choice_list'] = preg_replace('/[\n\r]*: <\/label>[\n\r]*/i', '</label>', $variables['choice_list']);
+  // All remaining form elements.
+  $variables['form_submit'] = drupal_render($form);
+
 }
 
 /**
diff --git modes/ranking.inc modes/ranking.inc
index 0be7883..a890480 100644
--- modes/ranking.inc
+++ modes/ranking.inc
@@ -171,28 +171,27 @@ function advpoll_voting_ranking_form(&$form_state, &$node, $teaser, $page, $stat
  *
  * @see advpoll-display-ranking-form.tpl.php
  */
-function template_preprocess_advpoll_voting_ranking_form(&$variables) {
+function advpoll_preprocess_advpoll_voting_ranking_form(&$variables) {
   $form = &$variables['form'];
   $variables['message'] = drupal_render($form['message']);
-    // If write-ins are used on this form.
+
+  // If write-ins are used on this form.
   if (isset($form['writein_choice'])) {
     $variables['writein_choice'] = drupal_render($form['writein_choice']);
   }
+
   $variables['form_id'] = $form['#id'];
-  // Every form element that should be carried in drag needs this class.
-  $variables['tabledrag_group_class'] = $form['#id'] . '-tabledrag-group';
-  foreach (element_children($form['choice']) as $i) {
-    $choice = &$variables['form']['choice'][$i];
-    // Add draggable class - TODO: fix this.
-    $choice['#attributes']['class'] = $variables['tabledrag_group_class'];
-    //$form['choice'][$i]['#attributes']['class'] = $variables['tabledrag_group_class'];
-  }
+
   // List of available choices in the poll.
   $variables['choice_list'] = drupal_render($form['choice']);
   // Take off the annoying colon & endlines that Drupal adds to each title.
   $variables['choice_list'] = preg_replace('/[\n\r]*: <\/label>[\n\r]*/i', '</label>', $variables['choice_list']);
   // All remaining form elements.
   $variables['form_submit'] = drupal_render($form);
+ 
+  // Add tabledrag JavaScript.
+  drupal_add_tabledrag($form['#id'] . '-table', 'order', 'self', 'advpoll-choice-order', NULL, NULL, FALSE);
+
 }
 
 function advpoll_view_results_ranking($node, $teaser, $page) {
