diff --git a/include/ajax.upgrader.php b/include/ajax.upgrader.php
index fa0b50a99c9c8271caf96e927c6032bbde4b9eee..92a3e6ef7884a47f9ae6d52a50606cf1f080acc4 100644
--- a/include/ajax.upgrader.php
+++ b/include/ajax.upgrader.php
@@ -25,7 +25,7 @@ class UpgraderAjaxAPI extends AjaxController {
         if(!$thisstaff or !$thisstaff->isAdmin() or !$ost)
             Http::response(403, 'Access Denied');
 
-        $upgrader = new Upgrader($ost->getDBSignature(), TABLE_PREFIX, PATCH_DIR);
+        $upgrader = new Upgrader($ost->getDBSignature(), TABLE_PREFIX, SQL_DIR);
 
         //Just report the next action on the first call.
         if(!$_SESSION['ost_upgrader'] || !$_SESSION['ost_upgrader'][$upgrader->getShash()]['progress']) {
diff --git a/include/class.dept.php b/include/class.dept.php
index 00609db105ccd781491997e61e5eb302aadfbfae..5516646129b348de5eba208d005c8ab87d2f4145 100644
--- a/include/class.dept.php
+++ b/include/class.dept.php
@@ -84,31 +84,32 @@ class Dept {
         return $this->ht['users'];
     }
 
-    function getNumMembers(){
+     
+    function getNumUsers(){
         return $this->getNumStaff();
     }
 
-    function getNumUsers(){
-        return $this->getNumStaff();
+    function getNumMembers(){
+        return count($this->getMembers());
     }
 
     function getMembers() {
 
-        if(!$this->members && $this->getNumStaff()) {
-            $sql='SELECT DISTINCT s.staff_id, s.dept_id FROM '.STAFF_TABLE.' s '
+        if(!$this->members) {
+            $this->members = array();
+            $sql='SELECT DISTINCT s.staff_id FROM '.STAFF_TABLE.' s '
                 .' LEFT JOIN '.GROUP_DEPT_TABLE.' g ON(s.group_id=g.group_id) '
-                .' INNER JOIN '.DEPT_TABLE.' d ON(d.dept_id=s.dept_id OR d.manager_id=s.staff_id OR d.dept_id=g.dept_id) '
+                .' INNER JOIN '.DEPT_TABLE.' d 
+                       ON(d.dept_id=s.dept_id 
+                            OR d.manager_id=s.staff_id 
+                            OR (d.dept_id=g.dept_id AND d.group_membership=1)
+                        ) '
                 .' WHERE d.dept_id='.db_input($this->getId())
                 .' ORDER BY s.lastname, s.firstname';
            
             if(($res=db_query($sql)) && db_num_rows($res)) {
-                while(list($staffId, $deptId)=db_fetch_row($res)) {
-                    if(!$this->enableGroupMembership() 
-                            && $deptId!=$this->getId() 
-                            && $staffId!=$this->getManagerId()) continue;
-
-                    $this->members[] = Staff::lookup($staffId);
-                }
+                while(list($id)=db_fetch_row($res))
+                    $this->members[] = Staff::lookup($id);
             }
         }
 
@@ -192,7 +193,7 @@ class Dept {
     }
 
 
-    function enableGroupMembership() {
+    function isGroupMembershipEnabled() {
         return ($this->ht['group_membership']);
     }
    
@@ -223,7 +224,7 @@ class Dept {
 
     function updateAllowedGroups($groups) {
 
-        if($groups) {
+        if($groups && is_array($groups)) {
             foreach($groups as $k=>$id) {
                 $sql='INSERT IGNORE INTO '.GROUP_DEPT_TABLE
                     .' SET dept_id='.db_input($this->getId()).', group_id='.db_input($id);
@@ -233,7 +234,7 @@ class Dept {
 
             
         $sql='DELETE FROM '.GROUP_DEPT_TABLE.' WHERE dept_id='.db_input($this->getId());
-        if($groups) 
+        if($groups && is_array($groups))  
             $sql.=' AND group_id NOT IN('.implode(',', db_input($groups)).')';
 
         db_query($sql);
diff --git a/include/class.group.php b/include/class.group.php
index e53cb8538f57edbdb78548c52bfc8cb75e8c7626..b13082be9f24301e12bf298cac0d043f86b7f8d1 100644
--- a/include/class.group.php
+++ b/include/class.group.php
@@ -86,7 +86,7 @@ class Group {
 
         if(!$this->members && $this->getNumUsers()) {
             $sql='SELECT staff_id FROM '.STAFF_TABLE
-                .' WHERE group_id='.db_input($this->getId()).' AND staff_id IS NOT NULL '
+                .' WHERE group_id='.db_input($this->getId())
                 .' ORDER BY lastname, firstname';
             if(($res=db_query($sql)) && db_num_rows($res)) {
                 while(list($id)=db_fetch_row($res))
@@ -116,7 +116,8 @@ class Group {
         
     function updateDeptAccess($depts) {
 
-        if($depts) {
+
+        if($depts && is_array($depts)) {
             foreach($depts as $k=>$id) {
                 $sql='INSERT IGNORE INTO '.GROUP_DEPT_TABLE
                     .' SET group_id='.db_input($this->getId())
@@ -126,7 +127,7 @@ class Group {
         }
 
         $sql='DELETE FROM '.GROUP_DEPT_TABLE.' WHERE group_id='.db_input($this->getId());
-        if($depts) // just inserted departments IF any.
+        if($depts && is_array($depts)) // just inserted departments IF any.
             $sql.=' AND dept_id NOT IN('.implode(',', db_input($depts)).')';
 
         db_query($sql);
diff --git a/include/upgrader/patches/02decaa2-60fcbee1.patch.sql b/include/upgrader/sql/02decaa2-60fcbee1.patch.sql
similarity index 100%
rename from include/upgrader/patches/02decaa2-60fcbee1.patch.sql
rename to include/upgrader/sql/02decaa2-60fcbee1.patch.sql
diff --git a/include/upgrader/patches/15af7cd3-98ae1ed2.patch.sql b/include/upgrader/sql/15af7cd3-98ae1ed2.patch.sql
similarity index 100%
rename from include/upgrader/patches/15af7cd3-98ae1ed2.patch.sql
rename to include/upgrader/sql/15af7cd3-98ae1ed2.patch.sql
diff --git a/include/upgrader/patches/2e20a0eb-98ae1ed2.patch.sql b/include/upgrader/sql/2e20a0eb-98ae1ed2.patch.sql
similarity index 100%
rename from include/upgrader/patches/2e20a0eb-98ae1ed2.patch.sql
rename to include/upgrader/sql/2e20a0eb-98ae1ed2.patch.sql
diff --git a/include/upgrader/patches/435c62c3-6007d45b.cleanup.sql b/include/upgrader/sql/435c62c3-2e7531a2.cleanup.sql
similarity index 100%
rename from include/upgrader/patches/435c62c3-6007d45b.cleanup.sql
rename to include/upgrader/sql/435c62c3-2e7531a2.cleanup.sql
diff --git a/include/upgrader/patches/435c62c3-6007d45b.patch.sql b/include/upgrader/sql/435c62c3-2e7531a2.patch.sql
similarity index 92%
rename from include/upgrader/patches/435c62c3-6007d45b.patch.sql
rename to include/upgrader/sql/435c62c3-2e7531a2.patch.sql
index a973c9b25b2bdaa343997df09f5ac3914f0fb64b..4fa5190600d05934df5669a781e89c775b6d1e1c 100644
--- a/include/upgrader/patches/435c62c3-6007d45b.patch.sql
+++ b/include/upgrader/sql/435c62c3-2e7531a2.patch.sql
@@ -8,7 +8,8 @@
 CREATE TABLE `%TABLE_PREFIX%group_dept_access` (
   `group_id` int(10) unsigned NOT NULL default '0',
   `dept_id` int(10) unsigned NOT NULL default '0',
-  PRIMARY KEY  (`group_id`,`dept_id`)
+  UNIQUE KEY `group_dept`  (`group_id`,`dept_id`),
+  KEY `dept_id` (`dept_id`)
 ) ENGINE=MyISAM;
 
 -- Extend membership to groups
diff --git a/include/upgrader/patches/49478749-c2d2fabf.patch.sql b/include/upgrader/sql/49478749-c2d2fabf.patch.sql
similarity index 100%
rename from include/upgrader/patches/49478749-c2d2fabf.patch.sql
rename to include/upgrader/sql/49478749-c2d2fabf.patch.sql
diff --git a/include/upgrader/patches/522e5b78-02decaa2.patch.sql b/include/upgrader/sql/522e5b78-02decaa2.patch.sql
similarity index 100%
rename from include/upgrader/patches/522e5b78-02decaa2.patch.sql
rename to include/upgrader/sql/522e5b78-02decaa2.patch.sql
diff --git a/include/upgrader/patches/60fcbee1-f8856d56.patch.sql b/include/upgrader/sql/60fcbee1-f8856d56.patch.sql
similarity index 100%
rename from include/upgrader/patches/60fcbee1-f8856d56.patch.sql
rename to include/upgrader/sql/60fcbee1-f8856d56.patch.sql
diff --git a/include/upgrader/patches/7be60a84-522e5b78.patch.sql b/include/upgrader/sql/7be60a84-522e5b78.patch.sql
similarity index 100%
rename from include/upgrader/patches/7be60a84-522e5b78.patch.sql
rename to include/upgrader/sql/7be60a84-522e5b78.patch.sql
diff --git a/include/upgrader/patches/98ae1ed2-e342f869.cleanup.sql b/include/upgrader/sql/98ae1ed2-e342f869.cleanup.sql
similarity index 100%
rename from include/upgrader/patches/98ae1ed2-e342f869.cleanup.sql
rename to include/upgrader/sql/98ae1ed2-e342f869.cleanup.sql
diff --git a/include/upgrader/patches/98ae1ed2-e342f869.patch.sql b/include/upgrader/sql/98ae1ed2-e342f869.patch.sql
similarity index 100%
rename from include/upgrader/patches/98ae1ed2-e342f869.patch.sql
rename to include/upgrader/sql/98ae1ed2-e342f869.patch.sql
diff --git a/include/upgrader/patches/a67ba35e-98ae1ed2.patch.sql b/include/upgrader/sql/a67ba35e-98ae1ed2.patch.sql
similarity index 100%
rename from include/upgrader/patches/a67ba35e-98ae1ed2.patch.sql
rename to include/upgrader/sql/a67ba35e-98ae1ed2.patch.sql
diff --git a/include/upgrader/patches/aa4664af-b19dc97d.patch.sql b/include/upgrader/sql/aa4664af-b19dc97d.patch.sql
similarity index 100%
rename from include/upgrader/patches/aa4664af-b19dc97d.patch.sql
rename to include/upgrader/sql/aa4664af-b19dc97d.patch.sql
diff --git a/include/upgrader/patches/abe9c0cb-bbb021fb.patch.sql b/include/upgrader/sql/abe9c0cb-bbb021fb.patch.sql
similarity index 100%
rename from include/upgrader/patches/abe9c0cb-bbb021fb.patch.sql
rename to include/upgrader/sql/abe9c0cb-bbb021fb.patch.sql
diff --git a/include/upgrader/patches/aee589ab-98ae1ed2.patch.sql b/include/upgrader/sql/aee589ab-98ae1ed2.patch.sql
similarity index 100%
rename from include/upgrader/patches/aee589ab-98ae1ed2.patch.sql
rename to include/upgrader/sql/aee589ab-98ae1ed2.patch.sql
diff --git a/include/upgrader/patches/b19dc97d-435c62c3.patch.sql b/include/upgrader/sql/b19dc97d-435c62c3.patch.sql
similarity index 100%
rename from include/upgrader/patches/b19dc97d-435c62c3.patch.sql
rename to include/upgrader/sql/b19dc97d-435c62c3.patch.sql
diff --git a/include/upgrader/patches/bbb021fb-49478749.patch.sql b/include/upgrader/sql/bbb021fb-49478749.patch.sql
similarity index 100%
rename from include/upgrader/patches/bbb021fb-49478749.patch.sql
rename to include/upgrader/sql/bbb021fb-49478749.patch.sql
diff --git a/include/upgrader/patches/c00511c7-7be60a84.cleanup.sql b/include/upgrader/sql/c00511c7-7be60a84.cleanup.sql
similarity index 100%
rename from include/upgrader/patches/c00511c7-7be60a84.cleanup.sql
rename to include/upgrader/sql/c00511c7-7be60a84.cleanup.sql
diff --git a/include/upgrader/patches/c00511c7-7be60a84.patch.sql b/include/upgrader/sql/c00511c7-7be60a84.patch.sql
similarity index 100%
rename from include/upgrader/patches/c00511c7-7be60a84.patch.sql
rename to include/upgrader/sql/c00511c7-7be60a84.patch.sql
diff --git a/include/upgrader/patches/c2d2fabf-aa4664af.patch.sql b/include/upgrader/sql/c2d2fabf-aa4664af.patch.sql
similarity index 100%
rename from include/upgrader/patches/c2d2fabf-aa4664af.patch.sql
rename to include/upgrader/sql/c2d2fabf-aa4664af.patch.sql
diff --git a/include/upgrader/patches/e342f869-c00511c7.patch.sql b/include/upgrader/sql/e342f869-c00511c7.patch.sql
similarity index 100%
rename from include/upgrader/patches/e342f869-c00511c7.patch.sql
rename to include/upgrader/sql/e342f869-c00511c7.patch.sql
diff --git a/include/upgrader/patches/f8856d56-abe9c0cb.patch.sql b/include/upgrader/sql/f8856d56-abe9c0cb.patch.sql
similarity index 100%
rename from include/upgrader/patches/f8856d56-abe9c0cb.patch.sql
rename to include/upgrader/sql/f8856d56-abe9c0cb.patch.sql
diff --git a/main.inc.php b/main.inc.php
index fb720f7cc1bf49710229d7bd0075d9571091c18d..6d30b7fce585c53f346824aa3a9233bc87311094 100644
--- a/main.inc.php
+++ b/main.inc.php
@@ -57,13 +57,13 @@
     define('SETUP_DIR',INCLUDE_DIR.'setup/');
 
     define('UPGRADE_DIR', INCLUDE_DIR.'upgrader/');
-    define('PATCH_DIR', UPGRADE_DIR.'patches/');
+    define('SQL_DIR', UPGRADE_DIR.'sql/');
 
     /*############## Do NOT monkey with anything else beyond this point UNLESS you really know what you are doing ##############*/
 
     #Current version && schema signature (Changes from version to version)
     define('THIS_VERSION','1.7-DPR4'); //Shown on admin panel
-    define('SCHEMA_SIGNATURE','6007d45b580c6ac0206514dbed0f28a6'); //MD5 signature of the db schema. (used to trigger upgrades)
+    define('SCHEMA_SIGNATURE','2e7531a201b5b8650dcd43681a832ebd'); //MD5 signature of the db schema. (used to trigger upgrades)
 
     #load config info
     $configfile='';
diff --git a/scp/upgrade.php b/scp/upgrade.php
index c424f425cc019acb864c74a393a7adb89827f26d..3bb850e837671a556996b1e8b0fb877fe53560f9 100644
--- a/scp/upgrade.php
+++ b/scp/upgrade.php
@@ -17,7 +17,7 @@ require_once 'admin.inc.php';
 require_once INCLUDE_DIR.'class.upgrader.php';
 
 //$_SESSION['ost_upgrader']=null;
-$upgrader = new Upgrader($cfg->getSchemaSignature(), TABLE_PREFIX, PATCH_DIR);
+$upgrader = new Upgrader($cfg->getSchemaSignature(), TABLE_PREFIX, SQL_DIR);
 $errors=array();
 if($_POST && $_POST['s'] && !$upgrader->isAborted()) {
     switch(strtolower($_POST['s'])) {
diff --git a/setup/inc/sql/osticket-v1.7-mysql.sql b/setup/inc/sql/osticket-v1.7-mysql.sql
index 662d749b16b3825ec20afd866cb516d77fb92b3e..21acfcfe83efe5b52d9ba5d9b153a87a25cc7eb9 100644
--- a/setup/inc/sql/osticket-v1.7-mysql.sql
+++ b/setup/inc/sql/osticket-v1.7-mysql.sql
@@ -365,7 +365,8 @@ DROP TABLE IF EXISTS `%TABLE_PREFIX%group_dept_access`;
 CREATE TABLE `%TABLE_PREFIX%group_dept_access` (
   `group_id` int(10) unsigned NOT NULL default '0',
   `dept_id` int(10) unsigned NOT NULL default '0',
-  PRIMARY KEY  (`group_id`,`dept_id`)
+  UNIQUE KEY `group_dept` (`group_id`,`dept_id`),
+  KEY `dept_id`  (`dept_id`)
 ) ENGINE=MyISAM;
 
 INSERT INTO `%TABLE_PREFIX%group_dept_access` (`group_id`, `dept_id`) VALUES
diff --git a/setup/inc/sql/osticket-v1.7-mysql.sql.md5 b/setup/inc/sql/osticket-v1.7-mysql.sql.md5
index bb0024a2a154824e26573a2133737345cadb433a..ad088e947dfe5eac019e5860c29e776bfabe60b1 100644
--- a/setup/inc/sql/osticket-v1.7-mysql.sql.md5
+++ b/setup/inc/sql/osticket-v1.7-mysql.sql.md5
@@ -1 +1 @@
-6007d45b580c6ac0206514dbed0f28a6
+2e7531a201b5b8650dcd43681a832ebd
diff --git a/setup/js/setup.js b/setup/js/setup.js
index b1f8e08c3aa48397206c43ad854fc3bf4815473c..7dd4c81aa5887c7388538e9dadd9f06927d1ac4b 100644
--- a/setup/js/setup.js
+++ b/setup/js/setup.js
@@ -18,47 +18,4 @@ jQuery(function($) {
         $('#overlay, #loading').show();
         return true;
         });
-
-    $('form#upgrade').submit(function(e) {
-        e.preventDefault();
-        var form = $(this);
-        $('input[type=submit]', this).attr('disabled', 'disabled');
-        $('#overlay, #loading').show();
-        doTasks('upgrade.php',form.serialize());
-
-        return false;
-        });
-
-    function doTasks(url, data) {
-        function _lp(count) {
-            $.ajax({
-                type: 'GET',
-                url: 'p.php',
-                async: true,
-                cache: false,
-                data: data,
-                dataType: 'text',
-                success: function(res) {
-                    if (res) { 
-                        $('#loading #msg').html(res);
-                    }
-                },
-                statusCode: {
-                    200: function() {
-                        setTimeout(function() { _lp(count+1); }, 2);
-                    },
-
-                    304: function() {
-                        $('#loading #msg').html("We're done... cleaning up!");
-                        setTimeout(function() { location.href =url;}, 3000);
-                    }
-                },
-                error: function() {
-                    $('#loading #msg').html("Something went wrong");
-                    setTimeout(function() { location.href =url;}, 1000);
-                }
-            });
-        };
-        _lp(0);
-    }
 });
diff --git a/setup/p.php b/setup/p.php
deleted file mode 100644
index 51c7055f257559099fd600ef12c31e882605873d..0000000000000000000000000000000000000000
--- a/setup/p.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/*********************************************************************
-    upgrader.php
-
-    osTicket Upgrader Helper - called via ajax.
-
-    Peter Rotich <peter@osticket.com>
-    Copyright (c)  2006-2012 osTicket
-    http://www.osticket.com
-
-    Released under the GNU General Public License WITHOUT ANY WARRANTY.
-    See LICENSE.TXT for details.
-
-    vim: expandtab sw=4 ts=4 sts=4:
-**********************************************************************/
-function staffLoginPage($msg) {
-    Http::response(403, $msg?$msg:'Access Denied');
-    exit;
-}
-
-require '../scp/staff.inc.php';
-if(!$thisstaff or !$thisstaff->isAdmin()) {
-    staffLoginPage('Admin Access Required!');
-    exit;
-}
-
-define('SETUPINC', true);
-define('INC_DIR', './inc/');
-define('SQL_DIR', INC_DIR.'sql/');
-
-require_once INC_DIR.'class.upgrader.php';
-
-
-$upgrader = new Upgrader($cfg->getSchemaSignature(), TABLE_PREFIX, SQL_DIR);
-
-//Just report the next action on the first call.
-if(!$_SESSION['ost_upgrader'][$upgrader->getShash()]['progress']) {
-    $_SESSION['ost_upgrader'][$upgrader->getShash()]['progress'] = $upgrader->getNextAction();
-    Http::response(200, $upgrader->getNextAction());
-    exit;
-}
-
-if($upgrader->getNumPendingTasks()) {
-    if($upgrader->doTasks() && !$upgrader->getNumPendingTasks() && $ost->isUpgradePending()) {
-        //Just reporting done...with tasks - break in between patches!
-        header("HTTP/1.1 304 Not Modified");
-        exit;
-    }
-} elseif($ost->isUpgradePending() && $upgrader->isUpgradable()) {
-    $version = $upgrader->getNextVersion();
-    if($upgrader->upgrade()) {
-        //We're simply reporting progress here - call back will report next action'
-        Http::response(200, "Upgraded to $version ... post-upgrade checks!");
-        exit;
-    }
-} elseif(!$ost->isUpgradePending()) {
-    $upgrader->setState('done');
-    session_write_close();
-    header("HTTP/1.1 304 Not Modified");
-    exit;
-}
-
-if($upgrader->isAborted() || $upgrader->getErrors()) {
-    Http::response(416, "We have a problem ... wait a sec.");
-    exit;
-}
-
-Http::response(200, $upgrader->getNextAction());
-?>