diff --git a/casetracker_mail.info b/casetracker_mail.info
index 63a897b..d38733b 100644
--- a/casetracker_mail.info
+++ b/casetracker_mail.info
@@ -1,5 +1,6 @@
 ; $Id$
 name = CT Mail
-package = Case Tracker
-dependencies = casetracker
 description = Enables mail sending and Mailhandler integration for Case Tracker.
+core = 6.x
+package = Case Tracker
+dependencies[] = casetracker
diff --git a/casetracker_mail.module b/casetracker_mail.module
index 3139777..3f03222 100644
--- a/casetracker_mail.module
+++ b/casetracker_mail.module
@@ -19,20 +19,15 @@ function casetracker_mail_help($section) {
 /**
  * Implementation of hook_menu().
  */
-function casetracker_mail_menu($may_cache) {
-  $items = array();
-
-  if ($may_cache) {
-    $items[] = array(
-      'access'             => user_access('administer case tracker'),
-      'callback'           => 'drupal_get_form',
-      'callback arguments' => 'casetracker_mail_settings',
-      'description'        => t('Configure the various Case Tracker mail options with these settings.'),
-      'path'               => 'admin/settings/casetracker/mail',
-      'title'              => t('CT Mail'),
-      'type'               => MENU_LOCAL_TASK,
-    );
-  }
+function casetracker_mail_menu() {
+  $items['admin/settings/casetracker/mail'] = array(
+    'access arguments'   => array('administer case tracker'),
+    'page callback'      => 'drupal_get_form',
+    'page arguments'     => array('casetracker_mail_settings'),
+    'description'        => t('Configure the various Case Tracker mail options with these settings.'),
+    'title'              => t('CT Mail'),
+    'type'               => MENU_LOCAL_TASK,
+  );
 
   return $items;
 }
@@ -46,97 +41,50 @@ function casetracker_mail_menu($may_cache) {
  *   The $comment array, passed only if this a comment has been left.
  */
 function casetracker_mail_send($case, $comment = NULL) {
-  global $user;
-
-  // is it a comment post
-  $isComment = !is_null($comment);
-
-  // get the project data
-  $pid = ($isComment)
-      ? $comment['prid']
-      : $case->pid;
-  $project = db_fetch_object(db_query("SELECT cp.project_number, n.title FROM {casetracker_project} cp LEFT JOIN {node} n ON (n.vid = cp.vid) WHERE cp.nid = %d", $pid));
-
-  // get the assigned to name
-  $assignToId = ($isComment)
-            ? $comment['assign_to']
-            : $case->assign_to;
-  $assignToName =  (is_numeric($assignToId))
-              ? casetracker_get_name($assignToId)
-              : $assignToId;
-
-  $variables = array(
-    '%project_id'       => $pid,
-    '%project_number'   => $project->project_number,
-    '%project_title'    => $project->title,
-    '%case_id'          => $case->nid,
-    '%case_number'      => $project->project_number .'-'. $case->case_number,
-    '%case_title'       => $isComment
-                ? $comment['case_title']
-                : $case->title,
-    '%case_type'        => casetracker_case_state_load(
-                'type',
-                $isComment
-                  ? $comment['case_type_id']
-                  : $case->case_type_id),
-    '%case_priority'    => casetracker_case_state_load(
-                'priority',
-                $isComment
-                  ? $comment['case_priority_id']
-                  : $case->case_priority_id),
-    '%case_status'      => casetracker_case_state_load(
-                'status',
-                $isComment
-                  ? $comment['case_status_id']
-                  : $case->case_status_id),
-    '%case_assigned'    => $assignToName,
-    '%case_author'      => casetracker_get_name($case->uid),
-    '%case_created'     => format_date($case->created, 'large'),
-    '%case_changed'     => format_date($case->changed, 'large'),
-    '%case_url'         => url('node/'.$case->nid, NULL, NULL, TRUE),
-    // @todo fails for CCK or non-body cases.
-    '%case_description' => _casetracker_mail_plain_description($case->body),
-    '%comment'          => NULL,
-  );
-
-
-
-  if (isset($comment)) { // make a master %comment variable that contains the values of this specific comment.
-    // @todo it'd be nice if we could display all the previous comments, as the project.module currently does.
-    $variables['%comment'] = strtr(variable_get('casetracker_mail_comment_message', _casetracker_mail_comment_message()), array(
-      '%comment_author'      => casetracker_get_name($comment['uid']),
-      '%comment_created'     => format_date($comment['date'], 'large'),
-      '%comment_title'       => $comment['subject'],
-      '%comment_description' => _casetracker_mail_plain_description($comment['comment']),
-    ));
-  }
-
   // make our own message ID so we can log it and allow responses via mailhandler.
   $msg_id = '<'. time() .'.'. mt_rand() .'@'. drupal_strtolower($_SERVER['SERVER_NAME']) .'>';
   $from    = variable_get('casetracker_mail_address', variable_get('site_mail', ini_get('sendmail_from')));
-  $subject = strtr(variable_get('casetracker_mail_subject', _casetracker_mail_subject()), $variables);
-  $body    = strtr(variable_get('casetracker_mail_case_message', _casetracker_mail_case_message()), $variables);
   db_query("INSERT INTO {casetracker_mail} (msg_id, nid, cid) VALUES ('%s', %d, %d)", $msg_id, $case->nid, isset($comment['cid']) ? $comment['cid'] : 0);
 
+  /* FIXME: just because $node->casetracker is an Array (when this function is
+    called through hook_nodeapi) and we wanna it to be an object. I guess it's a
+    nasty workaround. */
+  $case_casetracker = (object) $case->casetracker; 
+
+  // get the assigned to name
+  $assign_to_id = ($isComment)
+            ? $comment['casetracker']['assign_to']
+            : $case_casetracker->assign_to;
+  $assign_to_id = is_numeric($assign_to_id) ? $assign_to_id
+    : casetracker_get_uid($assign_to_id);
+
   // @todo this currently sends to only author and assigned. there needs to be
   // finer-grain control here, like an OG subscribers or all commenters, etc.
-  $results = db_query(
-    "SELECT uid, name, mail FROM {users} WHERE uid IN (%d, %d, %d)",
-    $comment['uid'],
-    $case->uid,
-    is_numeric($assignToId)
-      ? $assignToId
-      : casetracker_get_uid($assignToId)
-  );
+  $users_uids = array();
+  $users_uids[] = $case->uid;
+  if ($isComment) {
+    $users_uids[] = $comment['uid'];
+  }
+  if ($assign_to_id != 0) {
+    $users_uids[] = $assign_to_id;
+  }
+  $users = array_map("user_load", array_unique($users_uids));
 
-  while ($result = db_fetch_object($results)) {
-    if ($result->uid == $user->uid) { continue; } // don't fire to currently commenting user.
-    if (!$result->mail) { continue; } // don't fire blanks.
+  $params = array(
+    'case' => $case,
+    'comment' => $comment,
+    'assign_to_id' => $assign_to_id
+  );
 
+  foreach ($users as $u) {
     // if we get here a mail is send
-    $mail_status = drupal_mail('casetracker_mail', $result->mail, $subject, $body, $from, array('Message-ID' => $msg_id));
-    if (!$mail_status) { // mail failure doesn't actually tell us much, since PHP returns no error string, but hey, feel good, right?
-      watchdog('casetracker_mail', t('E-mail notification failed for %address.', array('%address' => $result->mail)));
+    $language = user_preferred_language($u);
+    $recipient = $u->mail;
+    print $recipient;
+    if (drupal_mail('casetracker_mail', 'update_case', $recipient, $language, $params)) {
+      watchdog('casetracker_mail', 'Sent email to %recipient', array('%recipient' => $recipient));
+    } else  { // mail failure doesn't actually tell us much, since PHP returns no error string, but hey, feel good, right?
+      watchdog('casetracker_mail', 'E-mail notification failed for %recipient.', array('%recipient' => $recipient));
     }
   }
 }
@@ -170,7 +118,6 @@ function casetracker_mail_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
     case 'insert':
     case 'update':
       if (in_array($node->type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE)) {
-        dvm('send');
         casetracker_mail_send($node);
       } break;
 
@@ -284,6 +231,80 @@ function casetracker_mail_settings() {
 }
 
 /**
+ * Implementation of hook_mail()
+ */
+function casetracker_mail_mail($key, &$message, $params)
+{
+  $case = $params['case'];
+  $comment = $params['comment'];
+  $assignToId = $params['assign_to_id'];
+
+  // is it a comment post
+  $isComment = !is_null($comment);
+
+  $assignToName =  (is_numeric($assignToId))
+              ? casetracker_get_name($assignToId)
+              : $assignToId;
+
+  /* FIXME: just because $node->casetracker is an Array (when this function is
+    called through hook_nodeapi) and we wanna it to be an object. I guess it's a
+    nasty workaround. */
+  $case_casetracker = (object) $case->casetracker;
+
+  // get the project data
+  $pid = ($isComment)
+      ? $comment['casetracker']['pid']
+      : $case_casetracker->pid;
+  $project = db_fetch_object(db_query("SELECT nid as project_number, title FROM {node} WHERE {node}.nid = %d", $pid));
+
+  $variables = array(
+    '%project_id'       => $pid,
+    '%project_number'   => $project->project_number,
+    '%project_title'    => $project->title,
+    '%case_id'          => $case->nid,
+    '%case_number'      => $project->project_number .'-'. $case->nid,
+    '%case_title'       => $case->title,
+    '%case_type'        => casetracker_case_state_load(
+                'type',
+                $isComment
+                  ? $comment['casetracker']['case_type_id']
+                  : $case_casetracker->case_type_id),
+    '%case_priority'    => casetracker_case_state_load(
+                'priority',
+                $isComment
+                  ? $comment['casetracker']['case_priority_id']
+                  : $case_casetracker->case_priority_id),
+    '%case_status'      => casetracker_case_state_load(
+                'status',
+                $isComment
+                  ? $comment['casetracker']['case_status_id']
+                  : $case_casetracker->case_status_id),
+    '%case_assigned'    => $assignToName,
+    '%case_author'      => casetracker_get_name($case->uid),
+    '%case_created'     => format_date($case->created, 'large'),
+    '%case_changed'     => format_date($case->changed, 'large'),
+    '%case_url'         => url('node/'.$case->nid, array('absolute' => TRUE)),
+    // @todo fails for CCK or non-body cases.
+    '%case_description' => _casetracker_mail_plain_description($case->body),
+    '%comment'          => NULL,
+  );
+
+  if (isset($comment)) { // make a master %comment variable that contains the values of this specific comment.
+    // @todo it'd be nice if we could display all the previous comments, as the project.module currently does.
+    $variables['%comment'] = strtr(variable_get('casetracker_mail_comment_message', _casetracker_mail_comment_message()), array(
+      '%comment_author'      => casetracker_get_name($comment['uid']),
+      '%comment_created'     => format_date($comment['date'], 'large'),
+      '%comment_title'       => $comment['subject'],
+      '%comment_description' => _casetracker_mail_plain_description($comment['comment']),
+    ));
+  }
+
+  $message['subject'] = strtr(variable_get('casetracker_mail_subject', _casetracker_mail_subject()), $variables);
+  $message['body'] = strtr(variable_get('casetracker_mail_case_message', _casetracker_mail_case_message()), $variables);
+  $message['headers']['Message-ID'] = $params['msg_id'];
+}
+
+/**
  * Returns the default message for Case Tracker case mails.
  */
 function _casetracker_mail_case_message() {
@@ -339,4 +360,4 @@ function _casetracker_mail_plain_description($_description) {
   $result = filter_xss($_description, array('dd'));
 
   return $result;
-}
\ No newline at end of file
+}
