diff --git a/subscriptions.admin.inc b/subscriptions.admin.inc
index 21473fe..e034650 100644
--- a/subscriptions.admin.inc
+++ b/subscriptions.admin.inc
@@ -215,7 +215,7 @@ function subscriptions_page_form_submit($form, &$form_state) {
     }
   }
   if (!empty($rid0)) {
-    $form_state['redirect'] = 'admin/settings/subscriptions/userdefaults/'. arg(4);
+    $form_state['redirect'] = 'admin/settings/subscriptions/userdefaults/'. subscriptions_arg(4);
     if ($rid0 != DRUPAL_AUTHENTICATED_RID) {
       $form_state['redirect'] .= '/'. $rid0;
     }
@@ -235,7 +235,7 @@ function subscriptions_page($account, $stype) {
     return;
   }
 
-  if (arg(0) == 'admin') {
+  if (subscriptions_arg(0) == 'admin') {
     $form['header'] = array(
       '#type'          => 'fieldset',
       '#title'         => t('Admin Information'),
@@ -251,11 +251,12 @@ function subscriptions_page($account, $stype) {
         );
 
       $tr = 't';
+      $rid = subscriptions_arg(5);
       $form['header']['role'] = array(
         '#type'        => 'fieldset',
         '#title'       => $tr('Roles'),
         '#collapsible' => TRUE,
-        '#collapsed'   => !is_numeric(arg(5)),
+        '#collapsed'   => !is_numeric($rid),
         );
       $form['header']['role']['header'] = array(
         '#type'          => 'markup',
@@ -265,7 +266,7 @@ function subscriptions_page($account, $stype) {
       $form['header']['role']['roles'] = array(
         '#type'          => 'select',
         '#title'         => t('Role(s)'),
-        '#default_value' => (is_numeric(arg(5))? arg(5) : DRUPAL_AUTHENTICATED_RID),
+        '#default_value' => (is_numeric($rid)? $rid : DRUPAL_AUTHENTICATED_RID),
         '#options'       => user_roles(TRUE),
         '#description'   => t('Select the role to load or role(s) to save.'),
         '#multiple'      => TRUE,
@@ -290,7 +291,7 @@ function subscriptions_page($account, $stype) {
     }
   }
   else {
-    subscriptions_suspended(arg(1), TRUE);
+    subscriptions_suspended(subscriptions_arg(1, 'uid'), TRUE);
     //if (variable_get('subscriptions_hide_overview_page', 0)) {
     //  $dummy_form_state = NULL;
     //  $form = subscriptions_user_suspend_form($dummy_form_state, $account);
@@ -462,7 +463,7 @@ function _subscriptions_suspended_alert($uid, $suspended) {
   switch ($suspended) {
     case 2:
       $msg = t('Your subscriptions have been suspended because your e-mail address does not work anymore!');
-      if (!(arg(0) == 'user' && arg(1) == $uid && arg(2) == 'edit')) {
+      if (!(subscriptions_arg(0) == 'user' && subscriptions_arg(1, 'uid') == $uid && subscriptions_arg(2) == 'edit')) {
         drupal_set_message($msg .'<br />'. t('Please go <a href="@path1">here</a> to update your e-mail address and then <a href="@path2">here</a> to resume delivery of your notifications.', array('@path1' => url("user/$uid/edit"), '@path2' => $path2)), 'error', FALSE);
       }
       else {
@@ -678,17 +679,15 @@ function subscriptions_user_settings_form(&$form_state, $account) {
  * @ingroup form
  */
 function subscriptions_user_settings_form_submit($form, &$form_state) {
+  $uid = subscriptions_arg(1, 'uid');
   if (isset($form_state['values']['reset']) && $form_state['values']['op'] == $form_state['values']['reset']) {
-    if (($uid = arg(1))> 0) {
+    if ($uid > 0) {
       db_query("UPDATE {subscriptions_user} SET digest = -1, send_interval = -1, send_updates = -1, send_comments = -1, send_interval_visible = -1, send_updates_visible = -1, send_comments_visible = -1, autosub_on_post = -1, autosub_on_update = -1, autosub_on_comment = -1, send_self = -1 WHERE uid = %d", $uid);
       drupal_set_message(t('The site defaults were restored.'));
     }
   }
   elseif ($form_state['values']['op'] == $form_state['values']['save']) {
-    if (arg(0) == 'user') {
-      $uid = arg(1);
-    }
-    else {
+    if (subscriptions_arg(0) != 'user') {
       $uid = -DRUPAL_AUTHENTICATED_RID;
       if (variable_get('subscriptions_hide_overview_page', 0) != $form_state['values']['hide_overview_page']) {
         variable_set('subscriptions_hide_overview_page', $form_state['values']['hide_overview_page']);
diff --git a/subscriptions.module b/subscriptions.module
index 27da1e5..9696424 100644
--- a/subscriptions.module
+++ b/subscriptions.module
@@ -25,10 +25,10 @@
  */
 function subscriptions_init() {
   define('SUBSCRIPTIONS_UNAVAILABLE', '<span class="error" title="'. t('(unavailable to regular users)') .'">&curren;</span>');
-  if (arg(0) == 'subscriptions' || arg(2) == 'subscriptions') {
+  if (subscriptions_arg(0) == 'subscriptions' || subscriptions_arg(2) == 'subscriptions') {
     include_once drupal_get_path('module', 'subscriptions') .'/subscriptions.admin.inc';  // TODO: do we need this?
   }
-  if (arg(0) == 's' && arg(1) == 'del') {
+  if (subscriptions_arg(0) == 's' && subscriptions_arg(1) == 'del') {
     $router_item = menu_get_item('subscriptions/rem/'. substr($_GET['q'], 6));
     if (isset($router_item) && $router_item['access']) {
       menu_set_item($_GET['q'], $router_item);
@@ -664,7 +664,7 @@ function subscriptions_suspended($uid, $alert = FALSE) {
  * @ingroup hooks
  */
 function subscriptions_form_user_profile_form_alter(&$form, &$form_state) {
-  subscriptions_suspended(arg(1), TRUE);
+  subscriptions_suspended(subscriptions_arg(1, 'uid'), TRUE);
 }
 
 /**
@@ -696,3 +696,23 @@ function _subscriptions_bulk_operation($uids, $bulk_op) {
   $_SESSION['subscriptions']['back_url'] = $_GET['q'];
   drupal_goto('admin/settings/subscriptions/userdefaults/bulk');
 }
+
+/**
+ * Return arg($index) in the proper way.
+ */
+function subscriptions_arg($index, $member_name = FALSE) {
+  $mgi = menu_get_item();
+  $arg = NULL;
+  if (isset($mgi['map'][$index])) {
+    $arg = $mgi['map'][$index];
+    if ($member_name) {
+      if (is_object($arg) && isset($arg->$member_name)) {
+        $arg = $arg->$member_name;
+      }
+      else {
+        $arg = NULL;
+      }
+    }
+  }
+  return $arg;
+}
diff --git a/subscriptions_blog_ui.module b/subscriptions_blog_ui.module
index 8ed6daf..febcbcf 100644
--- a/subscriptions_blog_ui.module
+++ b/subscriptions_blog_ui.module
@@ -105,7 +105,8 @@ function subscriptions_blog_ui_blog_form(&$form_state, $blogs, $account, $form)
     $uid = -DRUPAL_AUTHENTICATED_RID;
   }
   else {
-    $uid = (isset($account) ? $account->uid : (is_numeric(arg(5)) ? -arg(5) : -DRUPAL_AUTHENTICATED_RID));
+    $arg5 = subscriptions_arg(5);
+    $uid = (isset($account) ? $account->uid : (is_numeric($arg5) ? -$arg5 : -DRUPAL_AUTHENTICATED_RID));
     $result = db_query("
       SELECT s.value, s.send_interval, s.author_uid, s.send_comments, s.send_updates, u.name
       FROM {subscriptions} s
diff --git a/subscriptions_content.module b/subscriptions_content.module
index bd6ede5..bde1cb0 100644
--- a/subscriptions_content.module
+++ b/subscriptions_content.module
@@ -967,7 +967,8 @@ function subscriptions_content_type_form(&$form_state, $account, $form) {
     $uid = -DRUPAL_AUTHENTICATED_RID;
   }
   else {
-    $uid = (isset($account) ? $account->uid : (is_numeric(arg(5)) ? -arg(5) : -DRUPAL_AUTHENTICATED_RID));
+    $arg5 = subscriptions_arg(5);
+    $uid = (isset($account) ? $account->uid : (is_numeric($arg5) ? -$arg5 : -DRUPAL_AUTHENTICATED_RID));
     $result = db_query(db_rewrite_sql("
       SELECT s.value, s.send_interval, s.author_uid, s.send_comments, s.send_updates, nt.type, nt.name
       FROM {subscriptions} s
@@ -1135,7 +1136,7 @@ function subscriptions_content_mail_edit_tokens_list($mailkey, $options = array(
       }
       else {
         $tokens['!comments'] = $tokens['!comments'] . t('The rendering of the comments is defined by the !link.', array(
-                                                          '!link' => '<a href="../subscriptions_content_node-nid/'. check_plain(arg(4)) .'#edit-comment-body">'. t('comment templates') .'</a>'));
+                                                          '!link' => '<a href="../subscriptions_content_node-nid/'. check_plain(subscriptions_arg(4)) .'#edit-comment-body">'. t('comment templates') .'</a>'));
       }
   }
   return $tokens;
diff --git a/subscriptions_taxonomy.module b/subscriptions_taxonomy.module
index 0dea5f4..08c60cc 100644
--- a/subscriptions_taxonomy.module
+++ b/subscriptions_taxonomy.module
@@ -216,7 +216,8 @@ function subscriptions_taxonomy_taxa_form(&$form_state, $vocabularies, $account,
     $uid = -DRUPAL_AUTHENTICATED_RID;
   }
   else {
-    $uid = (isset($account) ? $account->uid : (is_numeric(arg(5)) ? -arg(5) : -DRUPAL_AUTHENTICATED_RID));
+    $arg5 = subscriptions_arg(5);
+    $uid = (isset($account) ? $account->uid : (is_numeric($arg5) ? -$arg5 : -DRUPAL_AUTHENTICATED_RID));
     $sql = db_rewrite_sql("
       SELECT s.value, s.send_interval, s.author_uid, s.send_comments, s.send_updates, t.tid, t.vid, t.name
       FROM {term_data} t
diff --git a/subscriptions_ui.module b/subscriptions_ui.module
index 171fcc7..96b07b4 100644
--- a/subscriptions_ui.module
+++ b/subscriptions_ui.module
@@ -16,9 +16,10 @@
 function subscriptions_ui_nodeapi(&$node, $op, $teaser) {
   global $user;
   if ($op == 'view' && $node->nid && !$teaser && subscriptions_ui_can_subscribe()) {
+    $op2 = subscriptions_arg(2);
     if (!variable_get('subscriptions_form_in_block', 0) &&
-        (!variable_get('subscriptions_form_link_only', 0) && (!arg(2) || arg(2) == 'view') ||
-          variable_get('subscriptions_form_link_only', 0) && arg(2) == 'subscribe' )) {
+        (!variable_get('subscriptions_form_link_only', 0) && (!$op2 || $op2 == 'view') ||
+          variable_get('subscriptions_form_link_only', 0) && $op2 == 'subscribe' )) {
       if ($form = drupal_get_form('subscriptions_ui_node_form', $node)) {
         $node->content['subscriptions_ui'] = array(
           '#value' => $form,
@@ -44,9 +45,10 @@ function subscriptions_ui_block($op = 'list', $delta = 0) {
       $blocks[0]['region'] = 'content';
       return $blocks;
     case 'view':
+      $op2 = subscriptions_arg(2);
       if (subscriptions_ui_can_subscribe() && variable_get('subscriptions_form_in_block', 0) &&
-          (!variable_get('subscriptions_form_link_only', 0) && (!arg(2) || arg(2) == 'view') ||
-            variable_get('subscriptions_form_link_only', 0) && arg(2) == 'subscribe' )) {
+          (!variable_get('subscriptions_form_link_only', 0) && (!$op2 || $op2 == 'view') ||
+            variable_get('subscriptions_form_link_only', 0) && $op2 == 'subscribe' )) {
         return array(
           'subject' => t('Subscriptions'),
           'content' => drupal_get_form('subscriptions_ui_node_form', menu_get_object()),
@@ -62,8 +64,9 @@ function subscriptions_ui_block($op = 'list', $delta = 0) {
  */
 function subscriptions_ui_can_subscribe() {
   global $user;
-  
-  return ($user->uid && arg(0) == 'node' && is_numeric(arg(1)) && module_invoke('subscriptions_ui', 'get_permission_to_handle', arg(1), 'subscriptions_ui') !== FALSE);
+
+  $arg1 = subscriptions_arg(1, 'nid');
+  return ($user->uid && subscriptions_arg(0) == 'node' && is_numeric($arg1) && module_invoke('subscriptions_ui', 'get_permission_to_handle', $arg1, 'subscriptions_ui') !== FALSE);
 }
 
 /**
@@ -78,7 +81,8 @@ function subscriptions_ui_link($type, $node = NULL, $teaser = NULL) {
   
   if ($type == 'node' && subscriptions_ui_can_subscribe() && empty($teaser)) {
     subscriptions_suspended($user->uid, TRUE);
-    if (variable_get('subscriptions_form_link_only', 0) && arg(2) != 'subscribe' && (!variable_get('subscriptions_avoid_empty_subscribe_links', 0) || module_invoke_all('subscriptions', 'node_options', $user, $node))) {
+    $arg2 = subscriptions_arg(2);
+    if (variable_get('subscriptions_form_link_only', 0) && $arg2 != 'subscribe' && (!variable_get('subscriptions_avoid_empty_subscribe_links', 0) || module_invoke_all('subscriptions', 'node_options', $user, $node))) {
       $blocked_types = variable_get('subscriptions_blocked_content_types', array());
       if (in_array($node->type, $blocked_types) && !user_access('subscribe to all content types')) {
         return;
@@ -91,7 +95,7 @@ function subscriptions_ui_link($type, $node = NULL, $teaser = NULL) {
         'attributes' => array('title' => t('Receive notifications about changes and/or comments to this page (and possibly similar pages).')),
       ));
     }
-    elseif (variable_get('subscriptions_form_in_block', 0) && arg(2) == 'subscribe') {
+    elseif (variable_get('subscriptions_form_in_block', 0) && $arg2 == 'subscribe') {
       // Make sure the block is visible
       global $theme;
       if (!isset($theme)) {
