diff --git a/plugins/sites_handler_filter_site.inc b/plugins/sites_handler_filter_site.inc
index d820fe0..228dd7e 100644
--- a/plugins/sites_handler_filter_site.inc
+++ b/plugins/sites_handler_filter_site.inc
@@ -12,4 +12,42 @@ class sites_handler_filter_site extends views_handler_filter_many_to_one {
       $this->value_options[$site->sid] = $site->title;
     }
   }
+
+  function value_form(&$form, &$form_state) {
+    parent::value_form($form, $form_state);
+    $form['display_all_nodes'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display nodes without attached sites'),
+      '#default_value' => isset($this->options['display_all_nodes']) ? $this->options['display_all_nodes'] : 0,
+      '#options' => array(1 => t('Yes'), 0 => t('No')),
+    );
+  }
+
+  function query() {
+    // adjust the last query
+    if ($this->options['display_all_nodes']) {
+      // make sure it is LEFT join
+      if ($this->relationship) {
+        $base_table = $this->view->query->relationships[$this->relationship]['table'];
+      }
+      else {
+        $base_table = $this->view->base_table;
+      }
+
+      $this->view->query->ensure_table('site_node', $this->relationship);
+      parent::query();
+
+      $where = $this->query->where[$this->options['group']];
+
+      $table = $this->ensure_my_table();
+      $clause = array_pop($where['clauses']);
+
+      $clause .= " OR $table.sid IS NULL";
+      $where['clauses'][] = $clause;
+
+      $this->query->where[$this->options['group']] = $where;
+    } else {
+      parent::query();
+    }
+  }
 }
diff --git a/plugins/sites_handler_filter_site_current.inc b/plugins/sites_handler_filter_site_current.inc
index 0f47261..052ee4a 100644
--- a/plugins/sites_handler_filter_site_current.inc
+++ b/plugins/sites_handler_filter_site_current.inc
@@ -1,7 +1,7 @@
 <?php
 
 class sites_handler_filter_site_current extends views_handler_filter {
-	
+
   function query() {
     $sid = context_get('sites','sid');
     if ($sid) {
@@ -15,7 +15,13 @@ class sites_handler_filter_site_current extends views_handler_filter {
       switch ($base_table) {
         case 'node':
           $table = $this->view->query->ensure_table('site_node', $this->relationship);
-          $this->view->query->add_where(0, "$table.sid = %d", $sid);
+
+          if (isset($this->options['display_all_nodes']) && $this->options['display_all_nodes']) {
+            $this->view->query->add_where(0, "$table.sid = %d OR $table.sid IS NULL", $sid);
+          }
+          else {
+            $this->view->query->add_where(0, "$table.sid = %d", $sid);
+          }
           break;
       }
     }
@@ -28,4 +34,13 @@ class sites_handler_filter_site_current extends views_handler_filter {
   function admin_summary() {
     return 'Current site';
   }
+
+  function value_form(&$form, &$form_state) {
+    $form['display_all_nodes'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display nodes without attached sites'),
+      '#default_value' => isset($this->options['display_all_nodes']) ? $this->options['display_all_nodes'] : 0,
+      '#options' => array(1 => t('Yes'), 0 => t('No')),
+    );
+  }
 }
diff --git a/site.inc b/site.inc
index ba07b70..3b46e5d 100644
--- a/site.inc
+++ b/site.inc
@@ -13,7 +13,7 @@ class site {
   var $front_page;
   var $menu_primary_links;
   var $menu_secondary_links;
-  
+
   function __construct($title = '', $purl_prefix = '', $front_page = '', $mpl = '', $msl = '', $sid = NULL) {
     $this->title = $title;
     $this->purl_prefix = $purl_prefix;
@@ -22,7 +22,7 @@ class site {
     $this->menu_secondary_links = $msl;
     $this->sid = $sid;
   }
-  
+
   function save() {
     if($this->sid == NULL) {
       if(count(_sites_get_sites()) == 0) {
@@ -36,12 +36,13 @@ class site {
     else {
       drupal_write_record('sites', $this, 'sid');
     }
-    
+
     $modifier = array(
       'provider' => 'sites',
       'id' => $this->sid,
       'value' => $this->purl_prefix,
     );
+
     purl_save($modifier);
   }
-}
\ No newline at end of file
+}
diff --git a/sites.admin.inc b/sites.admin.inc
index f336412..abbb294 100644
--- a/sites.admin.inc
+++ b/sites.admin.inc
@@ -7,15 +7,15 @@
  */
 function sites_list_sites() {
   $output = '<ul>';
-  
+
   $sites = _sites_get_sites();
   foreach($sites as $sid => $site) {
-      $output .= "<li><a href=\"/admin/build/sites/edit/$sid\">$site->title</a></li>";
+      $output .= "<li>" . l($site->title, 'admin/build/sites/edit/' . $site->sid) . "</li>";
   }
-  
+
   $output .= '</ul>';
-  $output .= '<a href="/admin/build/sites/add">Add a new site</a>';
-  
+  $output .= l(t('Add a new site'), 'admin/build/sites/add');
+
   return $output;
 }
 
@@ -30,15 +30,15 @@ function sites_site_form(&$form_state, $site_id = NULL) {
   else {
       $site = _sites_get_site($site_id);
   }
-  
+
   $form = array();
-  
+
   $form['sitename'] = array(
     '#title' => 'Site name',
     '#type' => 'textfield',
     '#default_value' => $site->title,
   );
-  
+
   $form['front_page'] = array(
     '#title' => 'Front page',
     '#description' => 'Leave blank to use sitewide frontpage',
@@ -59,20 +59,26 @@ function sites_site_form(&$form_state, $site_id = NULL) {
     '#type' => 'textfield',
     '#default_value' => $site->menu_secondary_links,
   );
-  
+
   // Add context prefix form
   $form['purl'] = purl_form('sites', $site_id, $site->purl_prefix);
-  
+
   $form['site_id'] = array(
     '#type' => 'hidden',
     '#value' => $site_id,
   );
-  
+
   $form['submit'] = array(
     '#value' => 'Submit',
     '#type' => 'submit',
   );
-  
+
+  if ($site_id) {
+    $form['delete'] = array(
+      '#value' => l('Delete','admin/build/sites/delete/' . $site_id),
+    );
+  }
+
   return $form;
 }
 
@@ -86,17 +92,40 @@ function sites_site_form_submit($form, &$form_state) {
   else {
     $site = _sites_get_site($form_state['values']['site_id']);
   }
-  
+
   $site->title = $form_state['values']['sitename'];
   $site->front_page = $form_state['values']['front_page'];
   $site->menu_primary_links = $form_state['values']['primary_links'];
   $site->menu_secondary_links = $form_state['values']['secondary_links'];
- 
+
   if (isset($form_state['values']['purl']['value'])) {
     $site->purl_prefix = $form_state['values']['purl']['value'];
   }
-  
+
   $site->save();
 }
 
+function sites_site_delete_form($form_state, $site_id) {
+  $site = _sites_get_site($site_id);
+  if (!$site) {
+    drupal_goto('admin/build/sites');
+    return;
+  }
+
+  $form = array();
+  $form['site_id'] = array(
+    '#type' => 'value',
+    '#value' => $site_id
+  );
 
+  $form = confirm_form($form, t('Do you want to delete site: @sitename ?', array('@sitename' => $site->title)), 'admin/build/sites');
+
+  return $form;
+}
+
+function sites_site_delete_form_submit($form,&$form_state) {
+  $site_id = $form_state['values']['site_id'];
+
+  _sites_delete_site($site_id);
+  $form_state['redirect'] = 'admin/build/sites';
+}
diff --git a/sites.core.inc b/sites.core.inc
index 76a1698..9693cab 100644
--- a/sites.core.inc
+++ b/sites.core.inc
@@ -10,10 +10,10 @@
  */
 function _sites_get_sites() {
   $sites = array();
-  
+
   $q = 'SELECT * FROM {sites}';
   $res = db_query($q);
-  
+
   while($row = db_fetch_object($res)) {
     $sites[$row->sid] = $row;
   }
@@ -35,12 +35,27 @@ function _sites_get_site($sid) {
     $q = 'SELECT * FROM {sites} s WHERE s.sid = %d LIMIT 1';
     $res = db_query($q, $sid);
     $obj = db_fetch_object($res);
-    
-    return new site($obj->title, $obj->purl_prefix, $obj->front_page, $obj->menu_primary_links, $obj->menu_secondary_links, $obj->sid);
+
+    if ($obj === FALSE) {
+      return NULL;
+    } else {
+      return new site($obj->title, $obj->purl_prefix, $obj->front_page, $obj->menu_primary_links, $obj->menu_secondary_links, $obj->sid);
+    }
   }
   else return NULL;
 }
 
+function _sites_delete_site($sid) {
+  db_query('DELETE FROM {sites} WHERE sid = %d',$sid);
+  db_query('DELETE FROM {site_node} WHERE sid = %d',$sid);
+
+  // delete PURL prefix
+  purl_delete(array(
+    'provider' => 'sites',
+    'id' => $sid,
+  ));
+}
+
 
 /**
  * Get the current site id.
diff --git a/sites.install b/sites.install
index 67f5820..dfd9422 100644
--- a/sites.install
+++ b/sites.install
@@ -34,12 +34,11 @@ function sites_schema() {
     'fields' => array(
       'sid' => array(
         'description' => t('The site id.'),
-        'type' => 'int',
+        'type' => 'serial',
         'unsigned' => TRUE,
         'not null' => TRUE,
         'primary key' => TRUE,
         'unique' => TRUE,
-        'default' => 0,
       ),
       'title' => array(
         'description' => t('The site\'s administrative title.'),
diff --git a/sites.module b/sites.module
index ed0268c..effb2ed 100644
--- a/sites.module
+++ b/sites.module
@@ -6,9 +6,11 @@ include(drupal_get_path('module', 'sites') . '/site.inc');
 include(drupal_get_path('module', 'sites') . '/sites.context.inc');
 include(drupal_get_path('module', 'sites') . '/sites.core.inc');
 include(drupal_get_path('module', 'sites') . '/sites.purl.inc');
-include(drupal_get_path('module', 'sites') . '/sites.admin.inc');
 include(drupal_get_path('module', 'sites') . '/sites.views.inc');
 
+function sites_init() {
+
+}
 
 /**
  * Implementation of hook_menu().
@@ -19,6 +21,7 @@ function sites_menu() {
     'description' => '',
     'page callback' => 'sites_list_sites',
     'access callback' => TRUE,
+    'file' => 'sites.admin.inc',
   );
 
   $items['admin/build/sites/add'] = array(
@@ -28,6 +31,7 @@ function sites_menu() {
     'page arguments' => array('sites_site_form'),
     'access callback' => TRUE,
     'type' => MENU_LOCAL_TASK,
+    'file' => 'sites.admin.inc',
   );
 
   $items['admin/build/sites/edit/%'] = array(
@@ -36,14 +40,21 @@ function sites_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('sites_site_form', 4),
     'access callback' => TRUE,
+    'file' => 'sites.admin.inc',
+  );
+
+  $items['admin/build/sites/delete/%'] = array(
+    'title' => 'Delete site',
+    'description' => '',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('sites_site_delete_form', 4),
+    'access callback' => TRUE,
+    'file' => 'sites.admin.inc',
   );
 
   return $items;
 }
 
-
-
-
 /**
  * Implementation of template_preprocess_page
  */
@@ -57,8 +68,6 @@ function sites_preprocess_page(&$vars) {
   }
 }
 
-
-
 /**
  * Implementation of hook_form_alter().
  */
@@ -74,19 +83,15 @@ function sites_form_alter(&$form, $form_state, $form_id) {
       }
 
       $default = array();
-      foreach($node->sites as $site) {
-        $default[$site->sid] = $site->sid;
+      if (isset($node->sites)) {
+        foreach($node->sites as $site) {
+          $default[$site->sid] = $site->sid;
+        }
       }
 
-      $form['sites_settings'] = array(
-        '#type' => 'fieldset',
-        '#access' => user_access('administer sites'),
+      $form['options']['sites'] = array(
         '#title' => t('Sites'),
-        '#collapsible' => FALSE,
-        '#collapsed' => FALSE,
-        '#weight' => 10,
-      );
-      $form['sites_settings']['sites'] = array(
+        '#description' => t('Select site to publish this node to. Leaving blank will allow node to be published everywhere.'),
         '#type' => 'select',
         '#size' => 5,
         '#multiple' => TRUE,
@@ -98,8 +103,6 @@ function sites_form_alter(&$form, $form_state, $form_id) {
   }
 }
 
-
-
 /**
  * Implementation of hook_nodeapi()
  */
@@ -108,14 +111,10 @@ function sites_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
     $node->sites = sites_get_node_sites($node->nid);
   }
   else if($op == 'insert' || $op == 'update') {
-    foreach($node->sites as $sid) {
-      _sites_attach_node_to_sites($node->nid, $node->sites);
-    }
+    _sites_attach_node_to_sites($node->nid, (array)$node->sites);
   }
 }
 
-
-
 /**
  * Implementation of hook_block()
  */
@@ -130,8 +129,6 @@ function sites_block($op = 'list', $delta = 0, $edit = array()) {
   // }
 }
 
-
-
 /**
  * Check the implementation of hook_sites_access with the heaviest weight
  * as to whether the node should be accessible.
@@ -151,20 +148,19 @@ function sites_access($node) {
   return $permitted;
 }
 
-
-
-
 /**
  * Implementation of hook_sites_access()
  */
 function sites_sites_access($node) {
-  if(in_array(sites_get_current_sid(), array_keys($node->sites))) return TRUE;
-  else return FALSE;
+  if(isset($node->sites) && count($node->sites)) {
+    return !in_array(sites_get_current_sid(), array_keys($node->sites));
+  }
+  else {
+    // allow all node can be access by any sites
+    return TRUE;
+  }
 }
 
-
-
-
 /**
  * Implementation of hook_menu_alter()
  */
@@ -172,13 +168,8 @@ function sites_menu_alter(&$items) {
   $items['node/%node']['access callback'] = 'sites_menu_access_override_node_view';
 }
 
-
-
 function sites_menu_access_override_node_view($op, $node) {
   if(!sites_access($node)) return FALSE;
   else return node_access($op, $node);
 }
 
-
-
-
diff --git a/sites.views.inc b/sites.views.inc
index 6b4f8cc..f41a7fe 100644
--- a/sites.views.inc
+++ b/sites.views.inc
@@ -32,7 +32,7 @@ function sites_views_handlers() {
 
 function sites_views_data() {
   $data = array();
-  $data['site_node']['table']['group']  = t('Node');
+  $data['site_node']['table']['group']  = t('Sites');
 
   $data['site_node']['table']['join'] = array(
     'site_node' => array(
@@ -48,7 +48,7 @@ function sites_views_data() {
   // sid field
   $data['site_node']['current_site_sid'] = array(
     'title' => t('Current site'),
-    'help' => t('The site ID'),
+    'help' => t('Filter node published in current site.'),
     'filter' => array(
       'title' => t('Current site'),
       'handler' => 'sites_handler_filter_site_current',
@@ -58,8 +58,8 @@ function sites_views_data() {
   );
 
   $data['site_node']['sid'] = array(
-    'title' => t('Site ID'),
-    'help' => t('Filter by site.'),
+    'title' => t('Sites'),
+    'help' => t('Filter node published on selected sites.'),
     'filter' => array(
       'handler' => 'sites_handler_filter_site',
     ),
@@ -68,4 +68,3 @@ function sites_views_data() {
   return $data;
 }
 
-
