diff --git a/mobile_tools.install b/mobile_tools.install
index 7628da8..5492b03 100755
--- a/mobile_tools.install
+++ b/mobile_tools.install
@@ -27,3 +27,12 @@ function mobile_tools_uninstall() {
   variable_del('mobile-tools-device-detection');
   variable_del('mobile-tools-device-capabilities');
 }
+
+/**
+ * Delete the unused mobile_tools_cookie_lifetime variable.
+ */
+function mobile_tools_update_6001() {
+  $ret = array();
+  variable_del('mobile_tools_cookie_lifetime');
+  return $ret;
+}
diff --git a/mobile_tools.module b/mobile_tools.module
index 5b23224..2a7b74f 100755
--- a/mobile_tools.module
+++ b/mobile_tools.module
@@ -355,14 +355,20 @@ function mobile_tools_get_device() {
   }
 
   // Checking the possible arguments
-  $session_time = time() + variable_get('mobile_tools_cookie_session', 3600 * 24 * 30);
+  $session_time = variable_get('mobile_tools_cookie_session', 3600 * 24 * 30);
+
+  // Cookie sessions set to zero are session cookies and will expire at the end
+  // of the session. For all other lengths, make valid by adding the current time.
+  if ($session_time > 0) {
+    $session_time = $session_time + time();
+  }
 
   //first check if the device type is forced in the device argument
   if (isset($_GET['device'])) {
     switch ($_GET['device']) {
       case 'desktop':
       case 'mobile':
-        setCookie('mt_device', $_GET['device'], variable_get('mobile_tools_cookie_lifetime', $session_time) , '/', $cookie_domain);
+        setCookie('mt_device', $_GET['device'], $session_time, '/', $cookie_domain);
         return array(
           'type' => $_GET['device'],
           'group' => '',
@@ -374,7 +380,7 @@ function mobile_tools_get_device() {
       default:
         $device_groups = mobile_tools_device_groups();
         if (isset($device_groups[$_GET['device']])) {
-          setCookie('mt_device', $_GET['device'], variable_get('mobile_tools_cookie_lifetime', $session_time) , '/', $cookie_domain);
+          setCookie('mt_device', $_GET['device'], $session_time, '/', $cookie_domain);
           return array(
             'type' => 'mobile',
             'group' => $_GET['device'],
@@ -397,7 +403,7 @@ function mobile_tools_get_device() {
       default:
         $device_groups = mobile_tools_device_groups();
         if (isset($device_groups[$_COOKIE['mt_device']])) {
-          setCookie('mt_device', $_COOKIE['mt_device'], variable_get('mobile_tools_cookie_lifetime', $session_time) , '/');
+          setCookie('mt_device', $_COOKIE['mt_device'], $session_time, '/');
           return array(
             'type' => 'mobile',
             'group' => $_COOKIE['mt_device'],
