diff --git a/bootstrap.php b/bootstrap.php
index 4b64227a839c1e9cd864db6cc74a1930e9906f98..2703395faa6a5548847cfa4590cbbf0f4067bc19 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -314,6 +314,9 @@ define('INCLUDE_DIR',ROOT_DIR.'include/'); //Change this if include is moved out
 define('PEAR_DIR',INCLUDE_DIR.'pear/');
 define('SETUP_DIR',ROOT_DIR.'setup/');
 
+define('CLIENTINC_DIR',INCLUDE_DIR.'client/');
+define('STAFFINC_DIR',INCLUDE_DIR.'staff/');
+
 define('UPGRADE_DIR', INCLUDE_DIR.'upgrader/');
 define('I18N_DIR', INCLUDE_DIR.'i18n/');
 define('CLI_DIR', INCLUDE_DIR.'cli/');
diff --git a/include/class.export.php b/include/class.export.php
index 85f021328a2d4a0ac7dccc9aa96f3b6738e3d8e1..4fc1bbf7bd1c2bcf00412ca74f1c45223fae4f2f 100644
--- a/include/class.export.php
+++ b/include/class.export.php
@@ -26,8 +26,8 @@ class Export {
 
     static function dumpQuery($sql, $headers, $how='csv', $options=array()) {
         $exporters = array(
-            'csv' => CsvResultsExporter,
-            'json' => JsonResultsExporter
+            'csv' => 'CsvResultsExporter',
+            'json' => 'JsonResultsExporter'
         );
         $exp = new $exporters[$how]($sql, $headers, $options);
         return $exp->dump();
diff --git a/include/class.http.php b/include/class.http.php
index b8205f5c96bc99075b3953b53c11e1ef5cbf97b0..b008eb6a7c281ea2569cb9b2e80f0e43177e61bb 100644
--- a/include/class.http.php
+++ b/include/class.http.php
@@ -42,7 +42,7 @@ class Http {
         if ($charset)
             $ct .= "; charset=$charset";
         header($ct);
-        if ($content) {
+        if (is_string($content)) {
             header('Content-Length: '.strlen($content)."\r\n\r\n");
             print $content;
             exit;
diff --git a/include/class.nav.php b/include/class.nav.php
index 02abcc028adbbe9ba3f486b149c14c99021e53a3..6cc44bd848d6ec5960a89e049944d5eb784cbcca 100644
--- a/include/class.nav.php
+++ b/include/class.nav.php
@@ -139,7 +139,7 @@ class StaffNav {
             $this->tabs['tickets'] = array('desc'=>__('Tickets'),'href'=>'tickets.php','title'=>__('Ticket Queue'));
 
             $this->tabs['kbase'] = array('desc'=>__('Knowledgebase'),'href'=>'kb.php','title'=>__('Knowledgebase'));
-            if (count($this->getRegisteredApps()))
+            if (!is_null($this->getRegisteredApps()))
                 $this->tabs['apps']=array('desc'=>__('Applications'),'href'=>'apps.php','title'=>__('Applications'));
         }
 
@@ -218,7 +218,7 @@ class AdminNav extends StaffNav{
             $tabs['manage']=array('desc'=>__('Manage'),'href'=>'helptopics.php','title'=>__('Manage Options'));
             $tabs['emails']=array('desc'=>__('Emails'),'href'=>'emails.php','title'=>__('Email Settings'));
             $tabs['staff']=array('desc'=>__('Agents'),'href'=>'staff.php','title'=>__('Manage Agents'));
-            if (count($this->getRegisteredApps()))
+            if (!is_null($this->getRegisteredApps()))
                 $tabs['apps']=array('desc'=>__('Applications'),'href'=>'apps.php','title'=>__('Applications'));
             $this->tabs=$tabs;
         }
diff --git a/include/class.orm.php b/include/class.orm.php
index 1325bbab7b23a6a55db15c02a70168a55b7e1771..45160c0180c54f1c00dd9dd7a6cfbd73a4eec812 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -1715,7 +1715,7 @@ implements ArrayAccess {
         throw new Exception(__('QuerySet is read-only'));
     }
 
-    function count() {
+    function count($mode=COUNT_NORMAL) {
         $this->asArray();
         return count($this->storage);
     }
diff --git a/include/client/templates/thread-entries.tmpl.php b/include/client/templates/thread-entries.tmpl.php
index 93843210969e4e3d79aea05b4ad692805dc5f95f..f54fa4f6b228243fb3a1c20588fd127752929082 100644
--- a/include/client/templates/thread-entries.tmpl.php
+++ b/include/client/templates/thread-entries.tmpl.php
@@ -2,6 +2,7 @@
 $events = $events
     ->filter(array('state__in' => array('created', 'closed', 'reopened', 'edited', 'collab')))
     ->order_by('id');
+$eventCount = count($events);
 $events = new IteratorIterator($events->getIterator());
 $events->rewind();
 $event = $events->current();
@@ -50,7 +51,7 @@ while ($event) {
 }
 
 // This should never happen
-if (count($entries) + count($events) == 0) {
+if (count($entries) + $eventCount == 0) {
     echo '<p><em>'.__('No entries have been posted to this thread.').'</em></p>';
 }
 ?>
diff --git a/include/pear/Mail/mimePart.php b/include/pear/Mail/mimePart.php
index 6ac85a2f8b9b9287754e65af2477ee8d4e4ef686..8588cd2b11b82cd78a17f38eb440768beee5f1b8 100644
--- a/include/pear/Mail/mimePart.php
+++ b/include/pear/Mail/mimePart.php
@@ -311,7 +311,7 @@ class Mail_mimePart
     {
         $encoded =& $this->encoded;
 
-        if (count($this->subparts)) {
+        if (!is_null($this->subparts)){
             $boundary = $boundary ? $boundary : '=_' . md5(rand() . microtime());
             $eol = $this->eol;
 
diff --git a/include/staff/profile.inc.php b/include/staff/profile.inc.php
index 78bab30bf2c38abdd2638522e96cc6526fa6cae1..a8a4a2a56d73e51d6206503dfbbc0aaa7a8c9191 100644
--- a/include/staff/profile.inc.php
+++ b/include/staff/profile.inc.php
@@ -209,7 +209,7 @@ if ($avatar->isChangeable()) { ?>
 
                   foreach($options as $k=>$v) {
                       echo sprintf('<option value="%s" %s>%s</option>',
-                                $k,($staff->default_from_name==$k)?'selected="selected"':'',$v);
+                                $k,($staff->default_from_name && $staff->default_from_name==$k)?'selected="selected"':'',$v);
                   }
                   ?>
                 </select>
diff --git a/include/staff/templates/queue-subnavigation.tmpl.php b/include/staff/templates/queue-subnavigation.tmpl.php
index fa33b7b7223e23097ee83b1b5a55013efea4c994..6fac6a5d006625ebc98df4dec4f9f3f95c373662 100644
--- a/include/staff/templates/queue-subnavigation.tmpl.php
+++ b/include/staff/templates/queue-subnavigation.tmpl.php
@@ -3,7 +3,7 @@
 // $q - <CustomQueue> object for this navigation entry
 // $children - <Array<CustomQueue>> all direct children of this queue
 $queue = $q;
-$hasChildren = count($children) > 0;
+$hasChildren = $children && (count($children) > 0);
 $selected = $_REQUEST['queue'] == $q->getId();
 global $thisstaff;
 ?>
diff --git a/include/staff/templates/thread-entries.tmpl.php b/include/staff/templates/thread-entries.tmpl.php
index 9b267bbae835c20484b484db1e963a1d4e5db2a0..c32417cd52ddcd1b4740521401974882402dfb5b 100644
--- a/include/staff/templates/thread-entries.tmpl.php
+++ b/include/staff/templates/thread-entries.tmpl.php
@@ -10,6 +10,7 @@ $cmp = function ($a, $b) use ($sort) {
 };
 
 $events = $events->order_by($sort);
+$eventCount = count($events);
 $events = new IteratorIterator($events->getIterator());
 $events->rewind();
 $event = $events->current();
@@ -62,7 +63,7 @@ foreach (Attachment::objects()->filter(array(
         $event = $events->current();
     }
     // This should never happen
-    if (count($entries) + count($events) == 0) {
+    if (count($entries) + $eventCount == 0) {
         echo '<p><em>'.__('No entries have been posted to this thread.').'</em></p>';
     }
     ?>