diff --git a/support.module b/support.module
index 1c14296..a4dc11f 100644
--- a/support.module
+++ b/support.module
@@ -11,9 +11,9 @@ define('SUPPORT_STATE_CLOSED', -3);
 function support_node_info() {
   return array(
     'support_ticket' => array(
-        'name' => t('Support ticket'),
-        'base' => 'support',
-        'description' => t('A <em>support ticket</em>.'),
+      'name' => t('Support ticket'),
+      'base' => 'support',
+      'description' => t('A <em>support ticket</em>.'),
     ),
   );
 }
@@ -78,7 +78,7 @@ function support_menu() {
     'title' => 'Edit',
     'type' => MENU_CALLBACK,
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('support_admin_client', 3),
+    'page arguments' => array('support_admin_client', 4),
     'access arguments' => array('administer support'),
     'file' => 'support.admin.inc',
   );
@@ -138,7 +138,7 @@ function support_menu() {
     0 => 'all',
     1 => 'all open',
     2 => 'my open',
-  ) + _support_states();
+      ) + _support_states();
 
   $result = db_query('SELECT clid, path, name FROM {support_client} WHERE status = :status AND parent = :parent', array(':status' => 1, ':parent' => 0));
   foreach ($result as $client) {
@@ -157,7 +157,7 @@ function support_menu() {
         'access callback' => 'support_access_clients',
         'access arguments' => array($client),
         'weight' => $sid,
-        'type' => $sid == 'all open' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
+        'type' => $sid == 1 ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
       );
     }
     $result2 = db_query('SELECT clid, path, name FROM {support_client} WHERE status = :status AND parent = :parent', array(':status' => 1, ':parent' => $client->clid));
@@ -412,11 +412,11 @@ function support_unsubscribe_user($node, $account, $key) {
     $lock = md5($account->uid . $node->nid);
     if ($key == $lock) {
       db_update('support_assigned')->fields(array(
-        'active' => 0,
-      ))
-      ->condition('uid', $account->uid)
-      ->condition('nid', $node->nid)
-      ->execute();
+            'active' => 0,
+          ))
+          ->condition('uid', $account->uid)
+          ->condition('nid', $node->nid)
+          ->execute();
       drupal_set_message(t('%email has been unsubscribed from ticket %ticket.', array('%email' => check_plain($account->mail), '%ticket' => check_plain($node->title))));
     }
     else {
@@ -428,10 +428,10 @@ function support_unsubscribe_user($node, $account, $key) {
     $lock = md5($account->uid);
     if ($key == $lock) {
       db_update('support_assigned')->fields(array(
-        'active' => 0,
-      ))
-      ->condition('uid', $account->uid)
-      ->execute();
+            'active' => 0,
+          ))
+          ->condition('uid', $account->uid)
+          ->execute();
       drupal_set_message(t('%email has been unsubscribed from all tickets.', array('%email' => check_plain($account->mail))));
     }
     else {
@@ -486,10 +486,10 @@ function support_ticket_load($nid) {
   static $tickets = array();
   if (!isset($tickets[$nid])) {
     $ticket = db_select('support_ticket', 't')
-      ->condition('nid', $nid)
-      ->fields('t')
-      ->execute()
-      ->fetchObject();
+        ->condition('nid', $nid)
+        ->fields('t')
+        ->execute()
+        ->fetchObject();
     drupal_alter('support_ticket_load', $ticket);
     $tickets[$nid] = $ticket;
   }
@@ -707,7 +707,7 @@ function support_form($node, $form_state) {
       '#maxlength' => 12,
       '#size' => 8,
       '#description' => t('Optionally specify another ticket id to move this ticket and all of its updates.  When moved, this ticket and all of its updates will become updates to the specified ticket and this ticket will be removed.  This action can not be undone.'),
-        '#access' => (user_access('administer support') || user_access('move ticket')),
+      '#access' => (user_access('administer support') || user_access('move ticket')),
     );
   }
 
@@ -828,24 +828,24 @@ function _support_node_insert_update($node) {
     }
   }
   $update = db_update('support_ticket')->fields(array(
-    'message_id' => isset($node->message_id) ? $node->message_id : '',
-    'state' => $node->state,
-    'priority' => $node->priority,
-    'client' => $node->client,
-    'assigned' => $node->assigned,
-  ))
-  ->condition('nid', $node->nid)
-  ->execute();
+        'message_id' => isset($node->message_id) ? $node->message_id : '',
+        'state' => $node->state,
+        'priority' => $node->priority,
+        'client' => $node->client,
+        'assigned' => $node->assigned,
+      ))
+      ->condition('nid', $node->nid)
+      ->execute();
   if ($update == 0) {
     db_insert('support_ticket')->fields(array(
-      'nid' => $node->nid,
-      'message_id' => isset($node->message_id) ? $node->message_id : '',
-      'state' => $node->state,
-      'priority' => $node->priority,
-      'client' => $node->client,
-      'assigned' => $node->assigned
-    ))
-    ->execute();
+          'nid' => $node->nid,
+          'message_id' => isset($node->message_id) ? $node->message_id : '',
+          'state' => $node->state,
+          'priority' => $node->priority,
+          'client' => $node->client,
+          'assigned' => $node->assigned
+        ))
+        ->execute();
   }
 
   if (isset($node->notifications) && !empty($node->notifications)) {
@@ -924,25 +924,31 @@ function _support_comment_insert_update($comment) {
       $comment->assigned = 0;
     }
   }
-  $update = db_update('support_ticket_comment')->fields(array(
-    'message_id' => isset($comment->message_id) ? $comment->message_id : '',
-    'state' => $comment->state,
-    'priority' => $comment->priority,
-    'client' => $comment->client,
-    'assigned' => $comment->assigned,
-  ))
-  ->condition('cid', $comment->cid)
-  ->execute();
-  if ($update == 0) {
+  $exists = db_select('support_ticket_comment', 't')
+          ->fields('t')
+          ->condition('t.cid', $comment->cid)
+          ->execute()->rowCount();
+  if ($exists) {
+    $update = db_update('support_ticket_comment')->fields(array(
+          'message_id' => isset($comment->message_id) ? $comment->message_id : '',
+          'state' => $comment->state,
+          'priority' => $comment->priority,
+          'client' => $comment->client,
+          'assigned' => $comment->assigned,
+        ))
+        ->condition('cid', $comment->cid)
+        ->execute();
+  }
+  else {
     db_insert('support_ticket_comment')->fields(array(
-      'cid' => $comment->cid,
-      'message_id' => isset($comment->message_id) ? $comment->message_id : '',
-      'state' => $comment->state,
-      'priority' => $comment->priority,
-      'client' => $comment->client,
-      'assigned' => $comment->assigned
-    ))
-    ->execute();
+          'cid' => $comment->cid,
+          'message_id' => isset($comment->message_id) ? $comment->message_id : '',
+          'state' => $comment->state,
+          'priority' => $comment->priority,
+          'client' => $comment->client,
+          'assigned' => $comment->assigned
+        ))
+        ->execute();
     // The first update to a ticket is not preserved in the database.
     // Store it in an array allowing other modules to dectect/respond to
     // ticket changes.
@@ -955,7 +961,8 @@ function _support_comment_insert_update($comment) {
   _support_comment_update_node($comment->nid);
 }
 
-function _support_comment_insert_update2($comment) {
+function _support_comment_insert_update2($node, $comment) {
+  global $user;
   // if admin, can update who is assigned to the ticket
   if (user_access('administer support') && (!isset($comment->support_email) || !$comment->support_email)) {
     if (isset($comment->subscribed_users) && !empty($comment->subscribed_users)) {
@@ -1008,12 +1015,12 @@ function support_comment_insert($comment) {
     // generate notification emails
     support_notification($comment, $comment->nid, 'ticket_comment_new', isset($comment->suppress) ? $comment->suppress : FALSE);
 
-    _support_comment_insert_update2($comment);
+    _support_comment_insert_update2($node, $comment);
   }
 }
 
 /**
- * Implementation of hook_comment_insert().
+ * Implementation of hook_comment_update().
  */
 function support_comment_update($comment) {
   if (is_array($comment)) {
@@ -1024,12 +1031,12 @@ function support_comment_update($comment) {
   }
   if ($node->type == 'support_ticket') {
     _support_comment_insert_update($comment);
-    _support_comment_insert_update2($comment);
+    _support_comment_insert_update2($node, $comment);
   }
 }
 
 /**
- * Implementation of hook_comment_insert().
+ * Implementation of hook_comment_delete().
  */
 function support_comment_delete($comment) {
   if (is_array($comment)) {
@@ -1042,8 +1049,8 @@ function support_comment_delete($comment) {
     // TODO Please review the conversion of this statement to the D7 database API syntax.
     /* db_query('DELETE FROM {support_ticket_comment} WHERE cid = %d', $comment->cid) */
     db_delete('support_ticket_comment')
-            ->condition('cid', $comment->cid)
-            ->execute();
+        ->condition('cid', $comment->cid)
+        ->execute();
     _support_comment_update_node($comment->nid);
   }
 }
@@ -1078,6 +1085,24 @@ function support_comment_validate($comment) {
 }
 
 /**
+ * Implementation of hook_comment_load().
+ */
+function support_comment_presave($comment) {
+  $result = db_select('support_ticket_comment', 'c')
+      ->fields('c')
+      ->condition('c.cid', $comment->cid)
+      ->execute();
+
+  foreach ($result as $record) {
+    $comment->message_id = $record->message_id;
+    $comment->state = $record->state;
+    $comment->priority = $record->priority;
+    $comment->client = $record->client;
+    $comment->assigned = $record->assigned;
+  }
+}
+
+/**
  * Implementation of hook_comment_view().
  */
 function support_comment_view($comment, $view_mode, $langcode) {
@@ -1089,12 +1114,11 @@ function support_comment_view($comment, $view_mode, $langcode) {
 
     drupal_add_css(drupal_get_path('module', 'support') . '/support-tickets.css');
 
-    $query = db_select('support_ticket_comment', 'c')
-      ->fields('c')
-      ->condition('c.cid', $comment->cid);
+    $query = db_select('support_ticket_comment', 't')
+        ->fields('t')
+        ->condition('t.cid', $comment->cid);
 
     $current = $query->execute()->fetchObject();
-
     if (!empty($current) && $assigned != $current->assigned) {
       $previous_account = user_load($assigned);
       $current_account = user_load($current->assigned);
@@ -1133,7 +1157,7 @@ function support_mail($key, &$message, $params) {
   $language = $message['language'];
   $variables = support_mail_tokens($params['account'], $language, $params['nid'], (isset($params['comment']) ? $params['comment'] : array()), $params['suppress']);
   $message['subject'] .= _support_mail_text($key . '_subject', $language, $variables, $params['integrate_email']);
-  $message['body'] = _support_mail_text($key . '_body', $language, $variables, $params['integrate_email']);
+  $message['body'] = array(_support_mail_text($key . '_body', $language, $variables, $params['integrate_email']));
   $node = node_load($params['nid']);
   $client = support_client_load($node->client);
   if ($client->integrate_email) {
@@ -1191,21 +1215,21 @@ function _support_node_move($node, $destination) {
   $thread = int2vancode(vancode2int($max) + 1) . '/';
   $account = user_load($node->uid);
   $id = db_insert('comment')->fields(array(
-    'nid' => $destination->nid,
-    'pid' => 0,
-    'uid' => $node->uid,
-    'subject' => $node->title,
-    'comment' => $node->body,
-    'format' => 1,
-    'hostname' => ip_address(),
-    'timestamp' => $node->changed,
-    'status' => 0,
-    'thread' => $thread,
-    'name' => $account->name,
-    'mail' => $account->mail,
-    'homepage' => $account->homepage,
-  ))
-  ->execute();
+        'nid' => $destination->nid,
+        'pid' => 0,
+        'uid' => $node->uid,
+        'subject' => $node->title,
+        'comment' => $node->body,
+        'format' => 1,
+        'hostname' => ip_address(),
+        'timestamp' => $node->changed,
+        'status' => 0,
+        'thread' => $thread,
+        'name' => $account->name,
+        'mail' => $account->mail,
+        'homepage' => $account->homepage,
+      ))
+      ->execute();
 
   // Tell the other modules a new comment has been submitted.
   $comment = array();
@@ -1239,16 +1263,16 @@ function _support_node_move($node, $destination) {
       // TODO Please review the conversion of this statement to the D7 database API syntax.
       /* db_query('DELETE FROM {upload} WHERE nid = %d', $node->nid) */
       db_delete('upload')
-              ->condition('nid', $node->nid)
-              ->execute();
+          ->condition('nid', $node->nid)
+          ->execute();
     }
     else {
       // transfer attachments to new node
       db_update('upload')->fields(array(
-        'nid' => $destination->nid,
-      ))
-      ->condition('nid', $node->nid)
-      ->execute();
+            'nid' => $destination->nid,
+          ))
+          ->condition('nid', $node->nid)
+          ->execute();
     }
   }
 
@@ -1261,21 +1285,21 @@ function _support_node_move($node, $destination) {
     $max = rtrim($thread, '/');
     $thread = int2vancode(vancode2int($max) + 1) . '/';
     $id = db_insert('comment')->fields(array(
-      'nid' => $destination->nid,
-      'pid' => 0,
-      'uid' => $update['uid'],
-      'subject' => $update['subject'],
-      'comment' => $update['comment'],
-      'format' => $update['format'],
-      'hostname' => $update['hostname'],
-      'timestamp' => $update['timestamp'],
-      'status' => $update['status'],
-      'thread' => $thread,
-      'name' => $update['name'],
-      'mail' => $update['mail'],
-      'homepage' => $update['homepage'],
-    ))
-    ->execute();
+          'nid' => $destination->nid,
+          'pid' => 0,
+          'uid' => $update['uid'],
+          'subject' => $update['subject'],
+          'comment' => $update['comment'],
+          'format' => $update['format'],
+          'hostname' => $update['hostname'],
+          'timestamp' => $update['timestamp'],
+          'status' => $update['status'],
+          'thread' => $thread,
+          'name' => $update['name'],
+          'mail' => $update['mail'],
+          'homepage' => $update['homepage'],
+        ))
+        ->execute();
     // Tell the other modules a new comment has been submitted.
     $update['cid'] = db_last_insert_id('comments', 'cid');
     $update['nid'] = $destination->nid;
@@ -1292,12 +1316,12 @@ function _support_node_move($node, $destination) {
     // transfer attachments to new comment
     if (module_exists('comment_upload')) {
       db_update('comment_upload')->fields(array(
-        'nid' => $destination->nid,
-        'cid' => $update['cid'],
-      ))
-      ->condition('nid', $node->nid)
-      ->condition('cid', $oldcid)
-      ->execute();
+            'nid' => $destination->nid,
+            'cid' => $update['cid'],
+          ))
+          ->condition('nid', $node->nid)
+          ->condition('cid', $oldcid)
+          ->execute();
     }
   }
   _comment_update_node_statistics($comment['nid']);
@@ -1323,12 +1347,12 @@ function support_mail_tokens($account, $language, $nid, $comment, $suppress) {
   $node = node_load($nid, NULL, $reset);
   $assigned = user_load($node->assigned);
   $reset = FALSE;
-  if (isset($comment['cid'])) {
-    $cid = $comment['cid'];
+  if (isset($comment->cid)) {
+    $cid = $comment->cid;
     // TODO Convert "user_load" to "user_load_multiple" if "$comment['uid']" is other than a uid.
     // To return a single user object, wrap "user_load_multiple" with "array_shift" or equivalent.
     // Example: array_shift(user_load_multiple(array(), $comment['uid']))
-    $update_account = user_load($comment['uid']);
+    $update_account = user_load($comment->uid);
   }
   else {
     $cid = 0;
@@ -1340,9 +1364,9 @@ function support_mail_tokens($account, $language, $nid, $comment, $suppress) {
   $client = support_client_load($node->client);
   $ticket_unsubscribe_key = md5($account->uid . $node->nid);
   $all_unsubscribe_key = md5($account->uid);
-  $previous_comment = db_query_range('SELECT cid FROM {comment} WHERE nid = :nid ORDER BY cid DESC', array(':nid' => $nid))->fetchField();
+  $previous_comment = db_query_range('SELECT cid FROM {comment} WHERE nid = :nid ORDER BY cid DESC', 0, 1, array(':nid' => $nid))->fetchField();
   if ($previous_comment) {
-    $previous = db_query('SELECT * FROM {support_ticket_comment} WHERE cid = :cid', array(':cid' => $previous_comment));
+    $previous = db_query('SELECT * FROM {support_ticket_comment} WHERE cid = :cid', array(':cid' => $previous_comment))->fetchObject();
   }
   // TODO Please change this theme call to use an associative array for the $variables parameter.
   $tokens = array(
@@ -1351,7 +1375,7 @@ function support_mail_tokens($account, $language, $nid, $comment, $suppress) {
     '!client_path' => $client->path,
     '!key' => '[' . variable_get('support_key', 'tkt') . ":$nid]",
     '!update_username' => isset($update_account->name) ? $update_account->name : '',
-    '!update_realname' => theme('username', $user, array('plain' => TRUE)),
+    '!update_realname' => theme('username', array('account' => $user)),
     '!site' => variable_get('site_name', 'Drupal'),
     '!uri' => $base_url,
     '!uri_brief' => preg_replace('!^https?://!', '', $base_url),
@@ -1359,14 +1383,14 @@ function support_mail_tokens($account, $language, $nid, $comment, $suppress) {
     '!mailto' => $account->mail,
     '!date' => format_date(REQUEST_TIME, 'medium', '', NULL, $language->language),
     '!ticket_subject' => check_plain($node->title),
-    '!ticket_body' => $suppress ? t('The text of this ticket was manually suppressed.  You must view the ticket online to see it.') . "\n" : drupal_html_to_text(check_markup($node->body) . _support_mail_list_attachments($node, $comment)),
+    '!ticket_body' => $suppress ? t('The text of this ticket was manually suppressed.  You must view the ticket online to see it.') . "\n" : drupal_html_to_text(check_markup($node->body[$node->language][0]['value']) . _support_mail_list_attachments($node, $comment)),
     '!ticket_url' => url("node/$nid", array('absolute' => TRUE, 'language' => $language, 'fragment' => "comment-$cid", 'alias' => variable_get('support_use_aliased_urls', TRUE))),
     '!update_url' => url("node/$nid", array('absolute' => TRUE, 'language' => $language, 'fragment' => "comment-form", 'alias' => variable_get('support_use_aliased_urls', TRUE))),
-    '!update' => $suppress ? t('The text of this ticket update was manually suppressed.  You must view the ticket online to see the update.') . "\n" : drupal_html_to_text(check_markup(isset($comment['comment']) ? $comment['comment'] : '') . _support_mail_list_attachments($node, $comment)),
+    '!update' => $suppress ? t('The text of this ticket update was manually suppressed.  You must view the ticket online to see the update.') . "\n" : drupal_html_to_text(check_markup(isset($comment->comment_body[$comment->language][0]) ? $comment->comment_body[$comment->language][0]['value'] : '') . _support_mail_list_attachments($node, $comment)),
     '!state' => ((isset($previous->state) && $previous->state != $node->state) ? _support_state($previous->state) . ' -> ' : '') . _support_state($node->state),
     '!priority' => ((isset($previous->priority) && $previous->priority != $node->priority) ? _support_priorities($previous->priority) . ' -> ' : '') . _support_priorities($node->priority),
     '!assigned_username' => !empty($assigned) ? $assigned->name : '',
-    '!assigned_realname' => !empty($assigned) ? theme('username', $assigned, array('plain' => TRUE)) : '',
+    '!assigned_realname' => !empty($assigned) ? theme('username', array('account' => $assigned)) : '',
     '!unsubscribe_ticket' => url("support/$nid/unsubscribe/$account->uid/$ticket_unsubscribe_key", array('absolute' => TRUE, 'language' => $language, 'alias' => variable_get('support_use_aliased_urls', TRUE))),
     '!unsubscribe_all' => url("support/all/unsubscribe/$account->uid/$all_unsubscribe_key", array('absolute' => TRUE, 'language' => $language, 'alias' => variable_get('support_use_aliased_urls', TRUE))),
   );
@@ -1386,11 +1410,12 @@ function _support_mail_list_attachments($node, $comment) {
       $attachments[] = url($file->filepath, array('absolute' => TRUE, 'alias' => variable_get('support_user_aliased_urls', TRUE)));
     }
   }
-  else if (isset($comment['files']) && is_array($comment['files'])) {
-    foreach ($comment['files'] as $fid => $file) {
-      $attachments[] = url($file['filepath'], array('absolute' => TRUE, 'alias' => variable_get('support_use_aliased_urls', TRUE)));
-    }
-  }
+  // TODO comment_upload dont has D7 port
+  // else if (isset($comment['files']) && is_array($comment['files'])) {
+  //  foreach ($comment['files'] as $fid => $file) {
+  //    $attachments[] = url($file['filepath'], array('absolute' => TRUE, 'alias' => variable_get('support_use_aliased_urls', TRUE)));
+  //  }
+  //}
   return (!empty($attachments) ? "<br />" . t('Attachments:') . "<br />" . implode("<br />", $attachments) : '');
 }
 
@@ -1476,7 +1501,7 @@ function support_save_message($message, $client) {
   }
   $ticket = support_ticket_load($message['nid']);
 
-  if (array_key_exists('headers') && is_object($message['headers']) && isset($message['headers']->message_id)) {
+  if (array_key_exists('headers', $message) && is_object($message['headers']) && isset($message['headers']->message_id)) {
     $message_id = $message['headers']->message_id;
   }
   else {
@@ -1491,56 +1516,56 @@ function support_save_message($message, $client) {
     // Finally, build the thread field for this new comment.
     $thread = int2vancode(vancode2int($max) + 1) . '/';
 
-    // TODO: format?
-    // TODO: ip_address?
-    $id = db_insert('comment')->fields(array(
-      'nid' => $ticket->nid,
-      'pid' => 0,
-      'uid' => $account->uid,
-      'subject' => $message['subject'],
-      'comment' => $message['body'],
-      'format' => 1,
-      'hostname' => ip_address(),
-      'timestamp' => REQUEST_TIME,
-      'status' => 0,
-      'thread' => $thread,
-      'name' => $account->name,
-      'mail' => $account->mail,
-      'homepage' => isset($account->homepage) ? $account->homepage : '',
-    ))
-    ->execute();
-
-    // Tell the other modules a new comment has been submitted.
-    $comment['cid'] = db_last_insert_id('comments', 'cid');
-    $comment['subject'] = $message['subject'];
-    $comment['comment'] = $message['body'];
-    $comment['nid'] = $ticket->nid;
-    $comment['uid'] = $account->uid;
-    $comment['message_id'] = $message_id;
-    $comment['state'] = isset($message['state']) ? $message['state'] : $ticket->state;
-    $comment['priority'] = isset($message['priority']) ? $message['priority'] : $ticket->priority;
-    $comment['client'] = $ticket->client;
-    $comment['assigned'] = isset($message['assigned']) ? $message['assigned'] : $ticket->assigned;
-    $comment['notification'] = db_query('SELECT active FROM {support_assigned} WHERE nid = :nid AND uid = :uid', array(':nid' => $ticket->nid, ':uid' => $account->uid))->fetchField();
-    $comment['support_email'] = TRUE;
-    $comment['files'] = _support_save_attachments($message['attachments'], $account);
+    $comment = new stdClass();
+    $comment->cid = NULL;
+    $comment->pid = 0;
+    $comment->uid = $account->uid;
+    $comment->nid = $ticket->nid;
+    $comment->status = COMMENT_PUBLISHED;
+    $comment->thread = $thread;
+    $comment->subject = $message['subject'];
+    $comment->hostname = ip_address();
+    $comment->language = LANGUAGE_NONE;
+    $comment->name = $account->name;
+    $comment->mail = $account->mail;
+    $comment->subject = $message['subject'];
+    $comment->timestamp = REQUEST_TIME;
+    $comment->comment_body = array(LANGUAGE_NONE => array($message['body']));
+// TODO
+// It seems http://drupal.org/project/comment_upload has no D7 port yet?
+// $comment->files = _support_save_attachments($message['attachments'], $account);
+    $comment->message_id = $message_id;
+    $comment->state = isset($message['state']) ? $message['state'] : $ticket->state;
+    $comment->priority = isset($message['priority']) ? $message['priority'] : $ticket->priority;
+    $comment->client = $ticket->client;
+    $comment->assigned = isset($message['assigned']) ? $message['assigned'] : $ticket->assigned;
+    $active = db_query('SELECT active FROM {support_assigned} WHERE nid = :nid AND uid = :uid', array(':nid' => $ticket->nid, ':uid' => $account->uid))->fetchField();
+    if ($active !== false)
+      $comment->notification = $active;
+    else
+      $comment->notification = 1;
+    $comment->support_email = 1;
     if (isset($message['suppress'])) {
-      $comment['suppress'] = $message['suppress'];
-    }
-    // convert indivudal files to arrays to work with the comment_upload module
-    foreach ($comment['files'] as $fid => $file) {
-      $comment['files'][$fid] = (array) $file;
-    }
-    if (isset($message['_support_extra_fields'])) {
-      foreach ($message['_support_extra_fields'] as $k => $v) {
-        $comment[$k] = $v;
-      }
-    }
-    comment_invoke_comment($comment, 'insert');
-
+      $comment->suppress = $message['suppress'];
+    }
+
+    comment_save($comment);
+
+    // TODO
+    // It seems http://drupal.org/project/comment_upload has no D7 port yet?
+    //  // convert indivudal files to arrays to work with the comment_upload module
+    //  foreach ($comment['files'] as $fid => $file) {
+    //   $comment['files'][$fid] = (array) $file;
+    //  }
+    //  if (isset($message['_support_extra_fields'])) {
+    //   foreach ($message['_support_extra_fields'] as $k => $v) {
+    //  $comment[$k] = $v;
+    //   }
+    //  }
+    //
     // Add an entry to the watchdog log.
-    watchdog('content', 'Comment: added %subject.', array('%subject' => $comment['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/' . $comment['nid'], array('fragment' => 'comment-' . $comment['cid'])));
-    _comment_update_node_statistics($comment['nid']);
+    watchdog('content', 'Comment: added %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid)));
+    _comment_update_node_statistics($comment->nid);
 
     // Clear the cache so an anonymous user can see his comment being added.
     cache_clear_all();
@@ -1553,7 +1578,6 @@ function support_save_message($message, $client) {
     $node->body = $message['body'];
     $node->type = 'support_ticket';
     $node->log = t('Support ticket created from email.');
-    $node->comment = COMMENT_NODE_READ_WRITE;
     $node->uid = $account->uid;
     $node->message_id = $message_id;
     $node->state = isset($message['state']) ? $message['state'] : _support_state_default();
@@ -1568,11 +1592,13 @@ function support_save_message($message, $client) {
       $node->files = _support_save_attachments($message['attachments'], $account);
     }
     $node->created_by_email = TRUE;
-    if (isset($message['_support_extra_fields'])) {
-      foreach ($message['_support_extra_fields'] as $k => $v) {
-        $node->{$k} = $v;
-      }
-    }
+    // TODO
+    // It seems http://drupal.org/project/comment_upload has no D7 port yet?
+    //  if (isset($message['_support_extra_fields'])) {
+    //    foreach ($message['_support_extra_fields'] as $k => $v) {
+    //      $node->{$k} = $v;
+    //    }
+    // }
     node_save($node);
   }
 }
@@ -1774,30 +1800,30 @@ function support_subscribe_user($nid, $uid, $active = 1) {
   $client = support_client_load($clid);
   $account = user_load($uid);
   if (support_access_clients($client, $account)) {
-    $update = db_update('support_assigned')->fields(array(
-      'active' => $active,
-    ))
-    ->condition('uid', $uid)
-    ->condition('nid', $nid)
-    ->execute();
-    if ($update == 0) {
-      db_insert('support_assigned')->fields(array(
-        'nid' => $nid,
-        'uid' => $uid,
-        'active' => $active
-      ))
-      ->execute();
+    $is_assigned = db_select('support_assigned', 'a')
+            ->condition('uid', $uid)
+            ->condition('nid', $nid)
+            ->fields('a')
+            ->execute()->rowCount();
+    if ($is_assigned) {
+      $update = db_update('support_assigned')
+          ->fields(array(
+            'active' => $active,
+          ))
+          ->condition('uid', $uid)
+          ->condition('nid', $nid)
+          ->execute();
     }
   }
   else {
     // If this user doesn't have permission to receive ticket updates,
     // be sure they are unsubscribed.
     db_update('support_assigned')->fields(array(
-      'active' => 0,
-    ))
-    ->condition('uid', $uid)
-    ->condition('nid', $nid)
-    ->execute();
+          'active' => 0,
+        ))
+        ->condition('uid', $uid)
+        ->condition('nid', $nid)
+        ->execute();
   }
 }
 
@@ -1863,8 +1889,8 @@ function _support_mail_notify($op, $account, $comment = array(), $nid = NULL, $s
     $node = node_load($nid);
     $params['account'] = $account;
     $params['nid'] = $nid;
-    if (isset($comment['cid'])) {
-      $params['cid'] = $comment['cid'];
+    if (isset($comment->cid)) {
+      $params['cid'] = $comment->cid;
       $params['comment'] = $comment;
     }
     else {
@@ -1892,14 +1918,16 @@ function _support_comment_update_node($nid) {
   $cid = db_query('SELECT MAX(cid) FROM {comment} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
   if ($cid) {
     $comment = db_select('support_ticket_comment', 't')->condition('t.cid', $cid)->fields('t')->execute()->fetchObject();
-    db_update('support_ticket')->fields(array(
-      'state' => $comment->state,
-      'priority' => $comment->priority,
-      'client' => $comment->client,
-      'assigned' => $comment->assigned,
-    ))
-    ->condition('nid', $nid)
-    ->execute();
+    if ($comment) {
+      db_update('support_ticket')->fields(array(
+            'state' => $comment->state,
+            'priority' => $comment->priority,
+            'client' => $comment->client,
+            'assigned' => $comment->assigned,
+          ))
+          ->condition('nid', $nid)
+          ->execute();
+    }
   }
 }
 
@@ -1912,7 +1940,7 @@ function support_form_alter(&$form, &$form_state, $form_id) {
       $node = node_load($form['nid']['#value']);
     }
     if (isset($node) && is_object($node) && isset($node->type) &&
-            $node->type == 'support_ticket') {
+        $node->type == 'support_ticket') {
       $reference = array();
       $form = array_merge(support_status_form($form_state, $form, ''), $form);
       $form = array_merge($form, support_subscribe_form($reference, $form, ''));
@@ -2154,18 +2182,18 @@ function support_search_execute($keys, $conditions) {
   $query = db_select('search_index', 'i')->extend('SearchQuery')->extend('PagerDefault');
   $query->join('node', 'n', 'n.nid = i.sid');
   $query
-          ->condition('n.status', 1)
-          ->condition('n.type', 'support_ticket')
-          ->addTag('node_access')
-          ->searchExpression($keys, 'node');
+      ->condition('n.status', 1)
+      ->condition('n.type', 'support_ticket')
+      ->addTag('node_access')
+      ->searchExpression($keys, 'node');
 
   // Add the ranking expressions.
   _node_rankings($query);
 
   // Add additional modifiers here...
   $find = $query
-          ->limit(10)
-          ->execute();
+      ->limit(10)
+      ->execute();
 
   // Load results.
   $results = array();
@@ -2200,15 +2228,15 @@ function support_search_execute($keys, $conditions) {
     $extra[] = _support_priorities($node->priority);
     $clients = support_search_available_clients();
     $results[] = array(
-        'link' => url('node/' . $item->sid, array('absolute' => TRUE)),
-        'type' => check_plain(node_type_get_name($node)),
-        'title' => $title,
-        'user' => theme('username', array('account' => $node)),
-        'date' => $node->changed,
-        'node' => $node,
-        'extra' => $extra,
-        'score' => $item->score / $total,
-        'snippet' => search_excerpt($keys, $node->body),
+      'link' => url('node/' . $item->sid, array('absolute' => TRUE)),
+      'type' => check_plain(node_type_get_name($node)),
+      'title' => $title,
+      'user' => theme('username', array('account' => $node)),
+      'date' => $node->changed,
+      'node' => $node,
+      'extra' => $extra,
+      'score' => $item->score / $total,
+      'snippet' => search_excerpt($keys, $node->body),
     );
   }
   return $results;
@@ -2219,8 +2247,8 @@ function support_search_execute($keys, $conditions) {
  */
 function support_search_info() {
   return array(
-      'title' => 'Tickets',
-      'path' => 'support',
+    'title' => 'Tickets',
+    'path' => 'support',
   );
 }
 
@@ -2477,7 +2505,7 @@ function _support_assigned($assigned, $node, $limit = 9999) {
     // can only unassign tickets if assigned to self, or have admin permissions
     // (always put this at the top of the array)
     if (!$assigned || $assigned == $user->uid ||
-            user_access('can assign tickets to any user') || user_access('administer support')) {
+        user_access('can assign tickets to any user') || user_access('administer support')) {
       $available["$assigned-$node->nid"] = array(0 => ' - ' . t('not assigned') . ' -') + $available["$assigned-$node->nid"];
     }
   }
@@ -2730,13 +2758,13 @@ function _support_priority_default() {
  */
 function _support_ticket_exists($account) {
   $result = db_select('node', 'n')
-    ->fields('n', array('nid', 'created'))
-    ->condition('type', 'support_ticket')
-    ->condition('status', 1)
-    ->condition('uid', $account->uid)
-    ->addTag('node_access')
-    ->execute()
-    ->fetchField();
+      ->fields('n', array('nid', 'created'))
+      ->condition('type', 'support_ticket')
+      ->condition('status', 1)
+      ->condition('uid', $account->uid)
+      ->addTag('node_access')
+      ->execute()
+      ->fetchField();
   return (bool) $result;
 }
 
@@ -2921,11 +2949,11 @@ function support_page_form($form, &$form_state, $client = NULL, $state = NULL) {
   $query->join('users', 'u', 'u.uid = n.uid');
   $query->leftjoin('comment', 'c', 'c.nid = n.nid');
   $query->condition(db_or()
-    ->condition('c.status', COMMENT_PUBLISHED)
-    ->isNull('c.status'))
-    ->condition('n.status', NODE_PUBLISHED)
-    ->condition('n.type', 'support_ticket')
-    ->condition('t.client', $client);
+          ->condition('c.status', COMMENT_PUBLISHED)
+          ->isNull('c.status'))
+      ->condition('n.status', NODE_PUBLISHED)
+      ->condition('n.type', 'support_ticket')
+      ->condition('t.client', $client);
 
   if (!user_access('view other users tickets') && !user_access('administer support') && !user_access('edit any ticket') && !user_access('delete any ticket')) {
     $query->condition('n.uid', $user->uid);
@@ -2970,10 +2998,10 @@ function support_page_form($form, &$form_state, $client = NULL, $state = NULL) {
   }
 
   $query->fields('n', array('nid', 'title', 'type', 'changed', 'uid'))
-    ->fields('u', array('name'))
-    ->fields('s', array('comment_count'))
-    ->fields('t', array('client', ' state', 'priority', 'assigned'))
-    ->addExpression('GREATEST(n.changed, s.last_comment_timestamp)', 'last_updated');
+      ->fields('u', array('name'))
+      ->fields('s', array('comment_count'))
+      ->fields('t', array('client', ' state', 'priority', 'assigned'))
+      ->addExpression('GREATEST(n.changed, s.last_comment_timestamp)', 'last_updated');
 
   $result = $query->execute();
 
@@ -3161,9 +3189,9 @@ function theme_support_page_form($variables) {
   }
   else {
     $rows[] = array(array(
-      'data' => t('No tickets available.'),
-      'colspan' => '9',
-    ));
+        'data' => t('No tickets available.'),
+        'colspan' => '9',
+        ));
   }
   if ($form['pager']['#markup']) {
     $output .= drupal_render($form['pager']);
