diff --git a/.gitignore b/.gitignore
index 63f65d5f0b3c3d5f65471ce1e149d9381e95482a..5e1185029e392f14f451c3432676b5eb528c3d24 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,8 @@ settings.inc.php
 *~
 views/*
 models/*
+components/*
+static/*
 cache/*
 meta/*
 meta/db.sqlite
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..bbff40132134aacae5aa504c00fb6823d0623db3
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright 2012 Alvaro Graves
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/README b/README
index c1f763fa7f246cbcee135b489bb7fcb7eb741fc2..6c4706e747030c79424f1ae9c55e51b041a500a9 100644
--- a/README
+++ b/README
@@ -1,13 +1,13 @@
-lodspeakr - Simple Publishing Kit for Linked Open Data
+lodspeakr - Linked Open Data Simple Publishing Kit
 author: Alvaro Graves (alvaro@graves.cl)
-version: 20120113
+version: 20120419 
 
 Simplest Installation
 ---------------------
 
-Just run
+Simply go to your web server root directory (e.g., /var/www), create a new folder, cd into it and run
 
-            bash < <(curl -s http://lodspeakr.org/install)
+   bash < <(curl -sL http://lodspeakr.org/install)
 
 Alternative methods of installation available at
 
diff --git a/classes/AbstractSpecialFunction.php b/classes/AbstractSpecialFunction.php
deleted file mode 100644
index 1865981a5ce7a0b57fd94037e6c5288db74bb26b..0000000000000000000000000000000000000000
--- a/classes/AbstractSpecialFunction.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?
-
-abstract class AbstractSpecialFunction{
-  abstract protected function getFunction($uri);
-  abstract protected function getParams($uri);
-  abstract public function execute($uri, $context);
-
-}
-
-?>
diff --git a/classes/BasicSpecialFunction.php b/classes/BasicSpecialFunction.php
deleted file mode 100644
index 3a4f2977bb5240796af156f3629d5c8720f48e50..0000000000000000000000000000000000000000
--- a/classes/BasicSpecialFunction.php
+++ /dev/null
@@ -1,119 +0,0 @@
-<?
-
-include_once('AbstractSpecialFunction.php');
-
-class SpecialFunction extends AbstractSpecialFunction{
-  protected function getFunction($uri){
-  	global $conf;
-  	$count = 1;
-  	$prefixUri = $conf['basedir'];
-  	$aux = str_replace($prefixUri, '', $uri, $count);
-  	$functionAndParams = explode('/', $aux);
-  	return $functionAndParams[0];
-  }
-  
-  protected function getParams($uri){
-  	global $conf;
-  	$count = 1;
-  	$prefixUri = $conf['basedir'];
-  	$functionAndParams = explode('/', str_replace($prefixUri, '', $uri, $count));
-  	if(sizeof($functionAndParams) > 1){
-  	  array_shift($functionAndParams);
-  	  return $functionAndParams;
-  	}else{
-  	  return array(null);
-  	}
-  }
-  
-  public function execute($uri, $context){
-  	global $conf;
-  	global $lodspk;
-  	global $results;
-  	global $rRoot;
-  	$f = $this->getFunction($uri);
-  	$params = array();
-  	$params = $this->getParams($uri);
-  	//$params[] = $context;
-  	$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
-  	$extension = Utils::getExtension($acceptContentType); 
-  	$args = array();
-  	try{
-  	  $viewFile = $conf['service']['prefix'].$f."/".$extension.".template";
-  	  $modelFile = $conf['service']['prefix'].$f."/".$extension.".queries";
-  	  if(!(is_dir($conf['model']['directory'].$modelFile) || is_file($conf['model']['directory'].$modelFile))){
-  	  	$msg = '<h1>Method does not exist!</h1><br/>This means that <tt>'.$modelFile."</tt> doesn't exist.<br/>Please refer to this tutorial to create one.<br/>";
-  	  	throw new Exception($msg);
-  	  }
-  	  if(!is_file($conf['view']['directory'].$viewFile)){
-  	  	  $msg='<h1>Method does not exist!</h1><br/>This means that <tt>'.$conf['view']['directory'].$viewFile."</tt> doesn't exist.<br/>Please refer to this tutorial to create one.<br/>";
-  	  	  throw new Exception($msg);
-  	  }
-  	  $endpoints = $context['endpoints'];
-  	  //array_pop($params);
-  	  //array_shift($params);
-  	  
-  	  $prefixHeader = array();
-
-  	  for($i=0;$i<sizeof($params);$i++){
-  	  	if($conf['mirror_external_uris']){
-  	  	  $altUri = Utils::curie2uri($params[$i]);
-  	  	  $altUri = preg_replace("|^".$conf['basedir']."|", $conf['ns']['local'], $altUri);
-  	  	  $params[$i] = Utils::uri2curie($altUri);
-  	  	}
-  	  }
-
-  	  for($i=0;$i<sizeof($params);$i++){  
-  	  	$auxPrefix = Utils::getPrefix($params[$i]);
-  	  	if($auxPrefix['ns'] != NULL){
-  	  	  $prefixHeader[] = $auxPrefix;
-  	  	}
-  	  	$args["arg".$i]=$params[$i];
-  	  }
-  	  $results['params'] = $params;
- 	  $lodspk = $conf['view']['standard'];
- 	  $lodspk['type'] = $modelFile;
- 	  $lodspk['root'] = $conf['root'];
- 	  $lodspk['home'] = $conf['basedir'];
- 	  $lodspk['this']['value'] = $uri;
- 	  $lodspk['this']['curie'] = Utils::uri2curie($uri);
- 	  $lodspk['this']['contentType'] = $acceptContentType;
- 	  $lodspk['model']['directory'] = $conf['model']['directory'];
- 	  $lodspk['view']['directory'] = $conf['view']['directory'];
- 	  $lodspk['ns'] = $conf['ns'];
- 	  $lodspk['endpoint'] = $conf['endpoint'];
-  	  $lodspk['type'] = $modelFile;
-  	  $lodspk['header'] = $prefixHeader;
-  	  $lodspk['args'] = $args;
-  	  $lodspk['module'] = 'service';
-  	  $lodspk['add_mirrored_uris'] = false;
-  	  $lodspk['baseUrl'] = $conf['basedir'];
-  	  $lodspk['this']['value'] = $uri;
-  	  $lodspk['this']['contentType'] = $acceptContentType;
-  	  $lodspk['view']['directory'] = $conf['home'].$conf['view']['directory'].$conf['service']['prefix'].$f.'/';
-  	  $lodspk['model']['directory'] = $conf['home'].$conf['model']['directory'];
-  	  chdir($conf['model']['directory']);
-  	  $first = array();
-  	  Utils::queryFile($modelFile, $endpoints['local'], $results, $first);
-  	  chdir($conf['home']);
-  	  $results = Utils::internalize($results);
-
-  	  if(is_array($results)){
-  	  	$results = Convert::array_to_object($results);
-  	  }
-  	  
-  	  //Need to redefine viewFile as 'local' i.e., inside service.foo/ so I can load files with the relative path correctly
-  	  $viewFile = $extension.".template";
-  	  Utils::processDocument($viewFile, $lodspk, $results);  
-  	  
-  	}catch (Exception $ex){
-  	  echo $ex->getMessage();
-  	  trigger_error($ex->getMessage(), E_ERROR);
-  	  Utils::send500($uri);
-  	}
-  	
-  }
-  
-}
-
-?>
-
diff --git a/classes/Endpoint.php b/classes/Endpoint.php
index 2393bb12cda31f3fec44d51240be503eda7aeea1..f31dd3e8156bfd151bd09026fa6f7996a0d780c2 100644
--- a/classes/Endpoint.php
+++ b/classes/Endpoint.php
@@ -31,12 +31,13 @@ class Endpoint{
         $url = $this->sparqlUrl.'?'.http_build_query($params, '', '&');
         curl_setopt($c, CURLOPT_URL, $url);
         curl_setopt($c, CURLOPT_HTTPHEADER, $context);
+        curl_setopt($c, CURLOPT_USERAGENT, "LODSPeaKr version ".$conf['version']);
         curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
         $aux = curl_exec($c); // execute the curl command 
         if($conf['debug']){
           if($aux == false){
-          	trigger_error("Error executing SPARQL query: ".curl_error($c), E_USER_ERROR);
-          	echo("Error executing SPARQL query: ".curl_error($c));
+          	trigger_error("Error executing SPARQL query (".$this->sparqlUrl."): ".curl_error($c), E_USER_ERROR);
+          	echo("Error executing SPARQL query (".$this->sparqlUrl."): ".curl_error($c));
           }
         }
         curl_close($c);
diff --git a/classes/HTTPStatus.php b/classes/HTTPStatus.php
new file mode 100644
index 0000000000000000000000000000000000000000..e062430684083149b82073019892bfb509eba988
--- /dev/null
+++ b/classes/HTTPStatus.php
@@ -0,0 +1,35 @@
+<? 
+
+class HTTPStatus{
+  
+  public static function send303($uri, $ext){
+  	header("HTTP/1.0 303 See Other");
+  	header("Location: ".$uri);
+  	header("Content-type: ".$ext);
+  	echo $uri."\n\n";
+  	exit(0);
+  }
+  
+  public static function send404($uri){
+  	header("HTTP/1.0 404 Not Found");
+  	echo "LODSPeaKr could not find ".$uri." or information about it.\nNo URIs in the triple store, or services configured with that URI\n";
+  	exit(0);
+  }
+  
+  public static function send406($uri){
+  	header("HTTP/1.0 406 Not Acceptable");
+  	echo "LODSPeaKr can't find a representation suitable for the content type you accept\n\n";
+  	exit(0);
+  }
+  
+  public static function send500($msg = null){
+  	header("HTTP/1.0 500 Internal Server Error");
+  	echo "An internal error ocurred. Please try later\n\n";
+  	if($msg != null){
+  	  echo $msg;
+  	}
+  	exit(0);
+  }
+}
+
+?>
diff --git a/classes/Importer.php b/classes/Importer.php
index 43931d962875d5791a90e9dd2407160495672388..9acba3df52c70b02d7ebd797991e4d2a872125ca 100644
--- a/classes/Importer.php
+++ b/classes/Importer.php
@@ -37,7 +37,7 @@ class Importer{
   	}elseif(isset($_POST['importtext'])){
   	  $parser->parse(RDF, $_POST['importtext']);
   	}else{
-  	  Utils::send500();
+  	  HTTPStatus::send500();
   	  exit(0);
   	}
   	$triples = $parser->getTriples();
diff --git a/classes/Utils.php b/classes/Utils.php
index 4398a4956b76c7c121d59fa46bf7628c82580de2..17c3641819614bdd0f779b3b8e7a5c2937c00e35 100644
--- a/classes/Utils.php
+++ b/classes/Utils.php
@@ -1,6 +1,7 @@
 <? 
 
 class Utils{
+<<<<<<< HEAD
   
   public static function send303($uri, $ext){
   	header("HTTP/1.0 303 See Other");
@@ -37,6 +38,9 @@ class Utils{
   	exit(0);
   }
   
+=======
+    
+>>>>>>> 190d4897be9d90712085169270a6e105600063f5
   public static function uri2curie($uri){
   	global $conf;
   	$ns = $conf['ns'];
@@ -122,7 +126,15 @@ class Utils{
   	  	  	  $row[$k]['uri'] = 1;
   	  	  	}elseif($v['type'] == 'bnode'){
   	  	  	  $row[$k]['curie'] = 'blankNode';
-  	  	  	}  	  	  	
+  	  	  	}else{
+  	  	  	  if($v['datatype']){
+  	  	  	    $row[$k]['type'] = $v['datatype'];
+  	  	  	  }
+  	  	  	  if($v['xml:lang']){
+  	  	  	    $row[$k]['lang'] = $v['xml:lang'];
+  	  	  	  }
+
+  	  	  	}
   	  	  }
   	  	  /*if(sizeof($aux) == 1){
   	  	  $obj = $row;
@@ -205,7 +217,7 @@ class Utils{
   	$ser;
   	$dPointer;
   	$docs = Utils::travelTree($data);
-  	require_once('lib/arc2/ARC2.php');
+  	require_once($conf['home'].'lib/arc2/ARC2.php');
   	$parser = ARC2::getRDFParser();
   	 $triples = array();
   	 
@@ -214,7 +226,7 @@ class Utils{
   	  $t = $parser->getTriples();
   	  $triples = array_merge($triples, $t);
   	}
-  	if($lodspk['add_mirrored_uris']){
+  	if($lodspk['mirror_external_uris']){
   	  global $uri;
   	  global $localUri;
   	  $t = array();
@@ -240,18 +252,25 @@ class Utils{
   	case 'rdf':
   	  $ser = ARC2::getRDFXMLSerializer();
   	  break;
+  	default:
+  	  $ser = null;
   	}
+  	if($ser != null){
   	$doc = $ser->getSerializedTriples($triples);
+  	}else{
+  	$doc = var_export($data, true);
+  	}
   	return $doc;
   }
   
   public static function processDocument($viewFile, $lodspk, $data){
   	global $conf;
+  	global $lodspk;
   	$contentType = $lodspk['contentType'];
   	$extension = Utils::getExtension($contentType); 
   	
   	header('Content-Type: '.$contentType);
-  	if($lodspk['resultRdf']){
+  	if(isset($lodspk['resultRdf']) && $lodspk['resultRdf'] == true){
   	  echo Utils::serializeRdf($data, $extension);
   	}else{
   	  Utils::showView($lodspk, $data, $viewFile);  	
@@ -267,7 +286,7 @@ class Utils{
   	}elseif(preg_match("/construct/i", $query)){
   	  return $conf['output']['describe'];
   	}else{
-  	  Utils::send500(null);
+  	  HTTPStatus::send500(null);
   	} 
   }
   
@@ -277,42 +296,47 @@ class Utils{
   	global $lodspk;
   	global $endpoints;
   	global $results;
+  	$strippedModelDir = str_replace('endpoint.', '', $modelDir); 	  
   	$lodspk['model'] = $modelDir;
   	$originalDir = getcwd();
   	$subDirs= array();
-  	trigger_error("Entering $modelDir from ".getcwd(), E_USER_NOTICE);
+  	trigger_error("Entering $strippedModelDir from ".getcwd(), E_USER_NOTICE);
   	chdir($modelDir);
   	$handle = opendir('.');
   	
   	while (false !== ($modelFile = readdir($handle))) {
   	  if($modelFile != "." && $modelFile != ".." && strpos($modelFile, ".") !== 0){
   	  	if(is_dir($modelFile)){
-  	  	  trigger_error("Save $modelFile for later, after all the queries in the current directory has been resolved", E_USER_NOTICE);
-  	  	  $subDirs[]=$modelFile;
-  	  	}else{
-  	  	  $e = null;
-  	  	  if(!isset($endpoints[$modelDir])){
-  	  	  	trigger_error("Creating endpoint for $modelDir", E_USER_NOTICE);
-  	  	  	if(!isset($conf['endpoint'][$modelDir])){
-  	  	  	  trigger_error("Couldn't find $modelDir as a list of available endpoints. Will continue using local", E_USER_WARNING);
-  	  	  	  $e = $endpoints['local'];
-  	  	  	}else{  
-  	  	  	  $endpoints[$modelDir] = new Endpoint($conf['endpoint'][$modelDir], $conf['endpoint']['config']);
-  	  	  	  $e = $endpoints[$modelDir];
-  	  	  	}
-  	  	  }else{
-  	  	  	$e = $endpoints[$modelDir];
+  	  	  if(strpos('endpoint.', $modelFile) == 0){
+  	  	  	trigger_error("Save $modelFile for later, after all the queries in the current directory has been resolved", E_USER_NOTICE);
+  	  	  	$subDirs[]=$modelFile;
   	  	  }
-  	  	  if($modelDir != $lodspk['type']){
-  	  	  	if(!isset($r[$modelDir]) ){
-  	  	  	  $r[$modelDir] = array();
-  	  	  	  $f[$modelDir] = array();
-  	  	  	}
-  	  	  	Utils::queryFile($modelFile, $e, $r[$modelDir], $f);
-  	  	  }else{
-  	  	  	Utils::queryFile($modelFile, $e, $r, $f);
+  	  	}else{
+  	  	  if(preg_match('/\.query$/', $modelFile)){
+  	  	    $e = null;
+  	  	    if(!isset($endpoints[$strippedModelDir])){
+  	  	      trigger_error("Creating endpoint for $strippedModelDir", E_USER_NOTICE);
+  	  	      if(!isset($conf['endpoint'][$strippedModelDir])){
+  	  	        trigger_error("Couldn't find $strippedModelDir as a list of available endpoints. Will continue using local", E_USER_WARNING);
+  	  	        $e = $endpoints['local'];
+  	  	      }else{  
+  	  	        $endpoints[$strippedModelDir] = new Endpoint($conf['endpoint'][$strippedModelDir], $conf['endpoint']['config']);
+  	  	        $e = $endpoints[$strippedModelDir];
+  	  	      }
+  	  	    }else{
+  	  	      $e = $endpoints[$strippedModelDir];
+  	  	    }
+  	  	    if($modelDir != $lodspk['type']){
+  	  	      if(!isset($r[$strippedModelDir]) ){
+  	  	        $r[$strippedModelDir] = array();
+  	  	        $f[$strippedModelDir] = array();
+  	  	      }
+  	  	      Utils::queryFile($modelFile, $e, $r[$strippedModelDir], $f);
+  	  	    }else{
+  	  	      Utils::queryFile($modelFile, $e, $r, $f);
+  	  	    }
   	  	  }
- 	  	}
+ 	  	  }
   	  }
   	}
   	closedir($handle);
@@ -323,13 +347,13 @@ class Utils{
   	  	  $r[$modelDir] = array();
   	  	}
   	  	if($modelDir != $lodspk['type']){
-  	  	  Utils::queryDir($v, $r[$modelDir], $f[$modelDir]);
+  	  	  Utils::queryDir($v, $r[$strippedModelDir], $f[$strippedModelDir]);
   	  	}else{
   	  	  Utils::queryDir($v, $r, $f);
   	  	}
   	  }  	
   	}
-  	chdir($conf['home']);
+  //	chdir($conf['home']);
   	//return $data;
   }
   
@@ -341,7 +365,7 @@ class Utils{
   	global $firstResults;
 	$uri = $lodspk['this']['value'];
   	$data = array();
-  	$strippedModelFile = str_replace('.query', '',$modelFile); 	  
+  	$strippedModelFile = str_replace('endpoint.', '', str_replace('.query', '',$modelFile)); 	  
  	if(!is_dir($modelFile)){
   	  require_once($conf['home'].'lib/Haanga/lib/Haanga.php');
   	  Haanga::configure(array(
@@ -361,7 +385,7 @@ class Utils{
  	  $vars = compact('uri', 'lodspk', 'models', 'first');
  	  $q = file_get_contents($modelFile);
  	  if($q == false){
- 	  	Utils::send500("I can't load ".$modelFile." in ".getcwd());
+ 	  	HTTPStatus::send500("I can't load ".$modelFile." in ".getcwd());
  	  }
  	  $fnc = Haanga::compile($q);
   	  $query = $fnc($vars, TRUE);
@@ -427,17 +451,19 @@ class Utils{
 	  	  	  //For now, assuming variables are in the GRAPH ?g
 	  	  	  $query = "CONSTRUCT {?g ?x ?y} WHERE{GRAPH ?g{?g ?x ?y}}";
 	  	  	}else{
-	  	  	  Utils::send500();
+	  	  	  HTTPStatus::send500();
 	  	  	}
 	  	  }else{
 	  	  	$query = preg_replace('/select\n?.*\n?where/i', 'CONSTRUCT {'.$construct.'} WHERE', $query);
 	  	  }
 	  	}else {
-	  	  Utils::send500("invalid query: " . $parser->getErrors());
+	  	  HTTPStatus::send500("invalid query: " . $parser->getErrors());
 	  	}
 	  }
+  	  $query = Utils::addPrefixes($query);
   	  if($conf['debug']){
-  	  	echo "$modelFile (against ".$e->getSparqlUrl().")\n-------------------------------------------------\n";
+  	  	echo "\n-------------------------------------------------\nIn ".getcwd()."\n";
+  	    echo "$modelFile (against ".$e->getSparqlUrl().")\n-------------------------------------------------\n\n";
   	  	echo $query;
   	  }
   	  trigger_error("Running query from ".$modelFile." on endpoint ".$e->getSparqlURL(), E_USER_NOTICE);
@@ -450,9 +476,6 @@ class Utils{
   	  	if(Utils::getResultsType($query) == $conf['output']['select']){
   	  	  $rPointer[$strippedModelFile] = Utils::sparqlResult2Obj($aux);
   	  	  $fPointer[$strippedModelFile] = $rPointer[$strippedModelFile][0];
-  	  	  /*if(sizeof($rPointer)>0){
-  	  	  $rPointer[$modelFile]['firstResults'] = $rPointer[$modelFile][0];
-  	  	  }*/
   	  	}else{
   	  	  $lodspk['resultRdf'] = true;
   	  	  $rPointer[$strippedModelFile] = $aux;
@@ -461,23 +484,23 @@ class Utils{
   	  	if(Utils::getResultsType($query) == $conf['output']['select']){
   	  	  $rPointer = Utils::sparqlResult2Obj($aux);
   	  	  $fPointer[$strippedModelFile] = $rPointer[0];
-  	  	  /*if(sizeof($rPointer)>0){
-  	  	  $rPointer['firstResults'] = $rPointer[0];
-  	  	  }*/
   	  	}else{
   	  	  $lodspk['resultRdf'] = true;
   	  	  $rPointer = $aux;
   	  	}  	 
   	  }
   	}else{
-  	  trigger_error("$modelFile is a directory, will process it later", E_USER_NOTICE);
-  	  if($modelFile != $lodspk['type']){
-  	  	if(!isset($rPointer[$strippedModelFile])){
-  	  	  $rPointer[$strippedModelFile] = array();
+  	  if(strpos('endpoint.', $modelFile) == 0){
+  	  	
+  	  	trigger_error("$modelFile is a directory, will process it later", E_USER_NOTICE);
+  	  	if($modelFile != $lodspk['type']){
+  	  	  if(!isset($rPointer[$strippedModelFile])){
+  	  	  	$rPointer[$strippedModelFile] = array();
+  	  	  }
+  	  	  Utils::queryDir($modelFile, $rPointer[$strippedModelFile], $fPointer[$strippedModelFile]);
+  	  	}else{
+  	  	  Utils::queryDir($modelFile, $rPointer, $fPointer);
   	  	}
-  	  	Utils::queryDir($modelFile, $rPointer[$strippedModelFile], $fPointer[$strippedModelFile]);
-  	  }else{
-  	  	Utils::queryDir($modelFile, $rPointer, $fPointer);
   	  }
   	}
   }
@@ -502,7 +525,7 @@ class Utils{
   	  	  	}elseif(is_string($conf['mirror_external_uris'])){
   	  	  	  $value['value'] = preg_replace("|^".$conf['mirror_external_uris']."|", $conf['basedir'], $value['value']);
   	  	  	}else{
-  	  	  	  Utils::send500("Error in mirroring configuration");
+  	  	  	  HTTPStatus::send500("Error in mirroring configuration");
   	  	  	  exit(1);
   	  	  	}
   	  	  }
@@ -514,12 +537,12 @@ class Utils{
   	return $array;
   }
   
-  public static function getfirstResultss($array){
+  public static function getfirstResults($array){
   	global $conf;
   	$firstResultsKeyAppearance = true;
   	foreach($array as $key => $value){
   	  if(!isset($value['value'])){
-  	  	$aux = Utils::getfirstResultss($value);
+  	  	$aux = Utils::getfirstResults($value);
   	  	if(isset($aux['0'])){
   	  	  $array[$key] = $aux['0'];
   	  	}else{
@@ -534,6 +557,7 @@ class Utils{
   public static function showView($lodspkData, $data, $view){
   	global $conf;
   	global $uri;
+  	global $lodspk;
   	global $extension;
   	//$lodspk = $conf['view']['standard'];
   	$lodspk = $lodspkData;
@@ -541,8 +565,11 @@ class Utils{
   	  $lodspk['this']['params'] = $lodspkData['params'];
   	}
   	require_once($conf['home'].'lib/Haanga/lib/Haanga.php');
+  	$viewAux = explode("/",$view);
+  	$viewFile = array_pop($viewAux);
+  	$viewPath = join("/", $viewAux);
   	Haanga::configure(array(
-  	  'template_dir' => $lodspk['view'],
+  	  'template_dir' => $conf['home'].$viewPath,
   	  'cache_dir' => $conf['home'].'cache/',
   	  ));
   	$models = $data;
@@ -556,12 +583,21 @@ class Utils{
  	}
 	if(is_string($data)){
 	  echo($data);
-	}elseif(is_file($lodspk['view'].$view)){
-	  Haanga::Load($view, $vars);
+	}elseif(is_file($conf['home'].$view)){
+         try{
+	  Haanga::Load($viewFile, $vars);
+          }catch(Exception $e){
+echo '<pre>';
+           echo $e->getMessage();
+var_dump($vars);
+echo($e->getMessage()."' in ".$e->getFile().":".$e->getLine()."\nStack trace:\n".$e->getTraceAsString());
+echo '</pre>';
+         }
 	}elseif($view == null){
 	  $fnc = Haanga::compile('{{models|safe}}');
 	  $fnc($vars, TRUE);
 	}else{
+	  echo $conf['home'].$viewPath." ".$viewFile;
 	  $fnc = Haanga::compile($view);
 	  $fnc($vars, TRUE);
 	}
@@ -587,6 +623,23 @@ class Utils{
   	return $triples;
   }
   
+  private static function addPrefixes($q){
+    global $conf;
+    $matches = array();
+    $visited = array();
+    $newQuery = $q;
+    if(preg_match_all("|\s(\w+):\w+|", $q, $matches) > 0){
+      foreach($matches[1] as $v){
+        if(!isset($visited[$v]) && isset($conf['ns'][$v])){
+          $newQuery = "PREFIX ".$v.": <".$conf['ns'][$v].">\n".$newQuery;
+          $visited[$v] = true;
+        }
+      }
+    }
+    
+    return $newQuery;
+  }
+  
 }
 
 ?>
diff --git a/classes/modules/serviceModule.php b/classes/modules/serviceModule.php
index d2cb174a5249916bda6b718a85739843a37cee83..99aa3147403bc59288e91b3413a28616a583d8a2 100644
--- a/classes/modules/serviceModule.php
+++ b/classes/modules/serviceModule.php
@@ -13,28 +13,46 @@ class ServiceModule extends abstractModule{
   	if(sizeof($qArr)==0){
   	  return FALSE;
   	}
-  	$extension = Utils::getExtension($acceptContentType); 
-  	$lodspk['model'] = $conf['home'].$conf['model']['directory'].$conf['service']['prefix'].$qArr[0].'/';
-  	$lodspk['view'] = $conf['home'].$conf['view']['directory'].$conf['service']['prefix'].$qArr[0].'/';
-  	$viewFile  = $extension.".template";
-  	$modelFile = $extension.".queries";
-  	if(file_exists($lodspk['model']) && file_exists($lodspk['view'])){
-  	  if(!file_exists($lodspk['view'].$viewFile)){
-  	  	$viewFile = null;  	  
+
+  	//Use .extension at the end of the service to force a particular content type
+  	if(strpos($qArr[0], '.')>0){
+  	  $aux = explode(".", $qArr[0]);
+  	  if(isset($aux[1])){
+  	    $contentTypes = $conf['http_accept'][$aux[1]];
+  	    if($contentTypes == null){
+  	      HTTPStatus::send406("Content type not acceptable\n");
+  	    }
+  	    $acceptContentType = $contentTypes[0];
+  	  }
+  	  $qArr[0] = $aux[0];
+  	}
+
+  	$extension = Utils::getExtension($acceptContentType);
+  	$viewFile  = null;
+  	$lodspk['model'] = $conf['model']['directory'].'/'.$conf['service']['prefix'].'/'.$qArr[0].'/';
+  	$lodspk['view'] = $conf['view']['directory'].'/'.$conf['service']['prefix'].'/'.$qArr[0].'/'.$extension.'.template';
+  	$lodspk['serviceName'] = $qArr[0];
+  	$modelFile = $lodspk['model'].$extension.'.queries';
+  	if(file_exists($lodspk['model'].$extension.'.queries')){
+  	  if(!file_exists($lodspk['view'])){
+  	  	$viewFile = null;
+  	  }else{
+  	  	$viewFile = $lodspk['view'];
   	  }
-  	  if(file_exists($lodspk['model'].$modelFile) && $qArr[0] != null){
-  	  	trigger_error("Using model ".$modelFile." and view ".$viewFile, E_USER_NOTICE);
-  	  	return array($modelFile, $viewFile);
-  	  }elseif($extension != 'html' && file_exists($lodspk['model'].'/html.queries')){
-  	  	$modelFile = 'html.queries';
-  	  	trigger_error("Using ".$modelFile." as model. It will be used as a CONSTRUCT", E_USER_NOTICE);
-  	  	return array($modelFile, $viewFile);
+  	  return array($modelFile, $viewFile);
+  	}elseif(file_exists($lodspk['model'].'queries')){
+ 	  $modelFile = $lodspk['model'].'queries';
+  	  if(!file_exists($lodspk['view'])){
+  	  	$lodspk['resultRdf'] = true;
+  	  	$viewFile = null;
   	  }else{
-  	  	Utils::send406($uri);
-  	  	exit(0);
+  	  	$viewFile = $lodspk['view'];
   	  }
+  	  return array($modelFile, $viewFile);
+  	}elseif(file_exists($lodspk['model'])){
+  	  HTTPStatus::send406($uri);
+  	  exit(0);
   	}
-  	
   	return FALSE;  
   }
   
@@ -49,17 +67,14 @@ class ServiceModule extends abstractModule{
   	$context = array();
   	$context['contentType'] = $acceptContentType;
   	$context['endpoints'] = $endpoints;
-  	//$sp = new SpecialFunction();
-  	//$sp->execute($localUri, $context);
   	$f = $this->getFunction($localUri);
   	$params = array();
   	$params = $this->getParams($localUri);
   	//$params[] = $context;
-  	$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
+  	//$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
   	$extension = Utils::getExtension($acceptContentType); 
   	$args = array();
   	list($modelFile, $viewFile) = $service;
-  	
   	try{
   	  $prefixHeader = array();
   	  
@@ -109,31 +124,33 @@ class ServiceModule extends abstractModule{
   	  if($viewFile == null){
   	  	$lodspk['transform_select_query'] = true;
   	  }
-  	  chdir($lodspk['model']);
+  	//  chdir($lodspk['model']);
   	  
   	  Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
       if(!$lodspk['resultRdf']){
       	$results = Utils::internalize($results); 
-      	$lodspk['firstResults'] = Utils::getfirstResultss($results);
+      	$firstAux = Utils::getfirstResults($results);
       	
-      	chdir($conf['home']);
+    //  	chdir($conf['home']);
       	if(is_array($results)){
       	  $resultsObj = Convert::array_to_object($results);
+      	  $results = $resultsObj;
       	}else{
       	  $resultsObj = $results;
       	}
+      	$lodspk['firstResults'] = Convert::array_to_object($firstAux);
       }else{
       	$resultsObj = $results;
       }
   	  
   	  //Need to redefine viewFile as 'local' i.e., inside service.foo/ so I can load files with the relative path correctly
   	  //$viewFile = $extension.".template";
-  	  chdir($conf['home']);  	  
+  	  //chdir($conf['home']);  	  
   	  Utils::processDocument($viewFile, $lodspk, $results);    	  
   	}catch (Exception $ex){
   	  echo $ex->getMessage();
   	  trigger_error($ex->getMessage(), E_ERROR);
-  	  Utils::send500($uri);
+  	  HTTPStatus::send500($uri);
   	}
   	exit(0);	
   }
diff --git a/classes/modules/staticModule.php b/classes/modules/staticModule.php
index 6f59daa99f936161d35499aaedb63ad200b1abba..c1c24130c186943bc2290d97a0883045ec041e9c 100644
--- a/classes/modules/staticModule.php
+++ b/classes/modules/staticModule.php
@@ -23,10 +23,37 @@ class StaticModule extends abstractModule{
   	global $uri;
   	global $acceptContentType;
   	global $endpoints;
-  	global $lodspk;
+  	global $lodspk;  	
+  	
   	header("Content-type: ");
-  	echo file_get_contents($conf['static']['directory'].$file);
+  	$uri = $localUri;
+  	if($conf['debug']){
+  	  echo "\n-------------------------------------------------\nIn ".$conf['static']['directory']."\n";
+  	  echo "Static file $file\n-------------------------------------------------\n\n";
+	  }
+	  if($conf['static']['haanga']){
+	    $lodspk['home'] = $conf['basedir'];
+	    $lodspk['baseUrl'] = $conf['basedir'];
+	    $lodspk['module'] = 'static';
+	    $lodspk['root'] = $conf['root'];
+	    $lodspk['contentType'] = $acceptContentType;
+	    $lodspk['ns'] = $conf['ns'];  	  	
+	    $lodspk['this']['value'] = $localUri;
+	    $lodspk['this']['curie'] = Utils::uri2curie($localUri);
+	    $lodspk['this']['local'] = $localUri;  	
+	    $lodspk['contentType'] = $acceptContentType;
+	    $lodspk['endpoint'] = $conf['endpoint'];	    
+	    $lodspk['type'] = $modelFile;
+	    $lodspk['header'] = $prefixHeader;
+	    $lodspk['baseUrl'] = $conf['basedir'];
+	    
+	    Utils::processDocument($conf['static']['directory'].$file, $lodspk, null);    	  
+  	}else{
+  	  echo file_get_contents($conf['static']['directory'].$file);
+  	}
   }
   
+  
+  
 }
 ?>
diff --git a/classes/modules/typeModule.php b/classes/modules/typeModule.php
index baa18b0bcb1ddc226b23ad072f48a41bf3712281..5bf22e26b1df316b790293e9bd89f7c278785dfb 100644
--- a/classes/modules/typeModule.php
+++ b/classes/modules/typeModule.php
@@ -15,17 +15,17 @@ class TypeModule extends abstractModule{
   	$metaDb = new MetaDb($conf['metadata']['db']['location']);
   	
   	$pair = Queries::getMetadata($localUri, $acceptContentType, $metaDb);
-  	
+
   	if($pair == NULL){ // Original URI is not in metadata
   	  if(Queries::uriExist($uri, $endpoints['local'])){
   	  	$page = Queries::createPage($uri, $localUri, $acceptContentType, $metaDb);
   	  	if($page == NULL){
-  	  	  Utils::send500("Can't write sqlite database.");
+  	  	  HTTPStatus::send500("Can't write sqlite database.");
   	  	}
-  	  	Utils::send303($page, $acceptContentType);
+  	  	HTTPStatus::send303($page, $acceptContentType);
   	  	exit(0);
   	  }else{
-  	  	return false; //Utils::send404($uri);
+  	  	return false;
   	  }
   	}
   	return $pair;
@@ -43,7 +43,7 @@ class TypeModule extends abstractModule{
   	list($res, $page, $format) = $pair;
   	//If resource is not the page, send a 303 to the document
   	if($res == $localUri){
-  	  Utils::send303($page, $acceptContentType);
+  	  HTTPStatus::send303($page, $acceptContentType);
   	}
   	
   	$uri = $res;
@@ -68,7 +68,7 @@ class TypeModule extends abstractModule{
   	if($viewFile == null){
   	  $lodspk['transform_select_query'] = true;
   	}
-
+  	
   	$lodspk['type'] = $modelFile;
   	$lodspk['home'] = $conf['basedir'];
   	$lodspk['baseUrl'] = $conf['basedir'];
@@ -78,24 +78,27 @@ class TypeModule extends abstractModule{
   	$lodspk['ns'] = $conf['ns'];
   	$lodspk['endpoint'] = $conf['endpoint'];
   	$lodspk['view'] = $conf['view']['directory'];
-
+  	
   	$lodspk['add_mirrored_uris'] = true;
   	$lodspk['this']['value'] = $uri;
   	$lodspk['this']['curie'] = Utils::uri2curie($uri);
   	$lodspk['this']['local'] = $localUri;
    	$lodspk['this']['extension'] = $extension;
-  	chdir($conf['home'].$conf['model']['directory']);
+  	//chdir($conf['home'].$conf['model']['directory']);
+  	
   	Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
     if(!$lodspk['resultRdf']){
   	  $results = Utils::internalize($results); 
-  	  $lodspk['firstResults'] = Utils::getfirstResultss($results);
+  	  $firstAux = Utils::getfirstResults($results);
   	  
-  	  chdir($conf['home']);
+  	  //chdir($conf['home']);
   	  if(is_array($results)){
   	  	$resultsObj = Convert::array_to_object($results);
+  	  	$results = $resultsObj;
   	  }else{
   	  	$resultsObj = $results;
   	  }
+  	  $lodspk['firstResults'] = Convert::array_to_object($firstAux);
   	}else{
   	  $resultsObj = $results;
   	}
@@ -112,49 +115,50 @@ class TypeModule extends abstractModule{
   	$objResult = array('modelFile' => null, 'viewFile' => null);
   	//Defining default views and models
   	$curieType="";
-/*  	$objResult['modelFile'] = 'main.query';
-  	$objResult['viewFile'] = 'html.template';
-  	$objResult['modelDir'] = $conf['model']['directory'].'type.rdfs:Resource/html.queries/';
-  	$objResult['viewDir'] = $conf['view']['directory'].'type.rdfs:Resource/'; 
-  */	
  	//Get the firstResults type available
   	$typesAndValues = array('rdfs:Resource' => -1);
-  	foreach($t as $v){
-  	  $curie = Utils::uri2curie($v);
-  	  $typesAndValues[$curie] = 0;
-  	  if(isset($conf['type']['priorities'][$curie]) && $conf['type']['priorities'][$curie] >= 0){
-  	  	$typesAndValues[$curie] = $conf['type']['priorities'][$curie];
+  	if($conf['disableComponents'] != true){
+  	  foreach($t as $v){
+  	  	$curie = Utils::uri2curie($v);
+  	  	$typesAndValues[$curie] = 0;
+  	  	if(isset($conf['type']['priorities'][$curie]) && $conf['type']['priorities'][$curie] >= 0){
+  	  	  $typesAndValues[$curie] = $conf['type']['priorities'][$curie];
+  	  	}
   	  }
   	}
   	arsort($typesAndValues);
+  	$extensionView = $extension.".";
+  	$extensionModel = '';
+  	if($extension != 'html'){
+  	  $extensionModel = $extension.'.';
+  	}
   	foreach($typesAndValues as $v => $w){
-  	  $auxModelFile = $conf['model']['directory'].$conf['type']['prefix'].$v.'/'.$extension.'.queries';
-  	  $auxViewFile = $conf['view']['directory'].$conf['type']['prefix'].$v.'/'.$extension.'.template'; 
+  	  $auxViewFile  = $conf['view']['directory'].'/'.$conf['type']['prefix'].'/'.$v.'/'.$extension.'.template';
+  	  $auxModelFile = $conf['model']['directory'].'/'.$conf['type']['prefix'].'/'.$v.'/'.$extension.'.queries';
   	  if($v == null){continue;}
   	  if(file_exists($auxModelFile)){
-  	  	$objResult['modelFile'] = $conf['type']['prefix'].$v.'/'.$extension.'.queries';
+  	  	$objResult['modelFile'] = $auxModelFile;//$conf['type']['prefix'].'/'.$v.'/'.$extensionModel.'queries';
   	  	if(file_exists($auxViewFile)){
-  	  	  $objResult['viewFile'] = $conf['type']['prefix'].$v.'/'.$extension.'.template';
+  	  	  $objResult['viewFile'] = $auxViewFile;//$conf['type']['prefix'].'/'.$v.'/'.$extensionView.'template';
   	  	}elseif($extension != 'html'){ //View doesn't exists (and is not HTML)
-  	  	  $objResult['viewFile'] = null;  	  	
+  	  	  $objResult['viewFile'] = null;
   	  	}
   	  	return $objResult;
-  	  }elseif($extension != 'html' &&
-  	  	file_exists($conf['model']['directory'].$conf['type']['prefix'].$v.'/html.queries')){
-	  $objResult['modelFile'] = $conf['type']['prefix'].$v.'/html.queries';
-  	  if(file_exists($auxViewFile) ){
-  	  	$objResult['viewFile'] = $conf['type']['prefix'].$v.'/'.$extension.'.template';
-  	  }else{
-  	  	$lodspk['transform_select_query'] = true;
-  	  	$objResult['viewFile'] = null;
-  	  }
-  	  trigger_error("LODSPeaKr can't find the proper query. Using HTML query instead.", E_USER_NOTICE);
-  	  break;
+  	  }elseif(file_exists($conf['model']['directory'].'/'.$conf['type']['prefix'].'/'.$v.'/queries')){
+  	  	$objResult['modelFile'] = $conf['model']['directory'].'/'.$conf['type']['prefix'].'/'.$v.'/queries';
+  	  	if(file_exists($auxViewFile) ){
+  	  	  $objResult['viewFile'] = $auxViewFile;
+  	  	}else{
+  	  	  $lodspk['transform_select_query'] = true;
+  	  	  $objResult['viewFile'] = null;
   	  	}
+  	  	trigger_error("LODSPeaKr can't find the proper query. Using HTML query instead.", E_USER_NOTICE);
+  	  	break;
+  	  }
   	}
-  	if($objResult['viewFile'] == null && $extension == 'html'){
+  	/*if($objResult['viewFile'] == null && $extensionView == 'html'){
   	  $objResult['viewFile'] = 'html.template';
-  	}
+  	}*/
   	return $objResult;
   }
   
diff --git a/classes/modules/uriModule.php b/classes/modules/uriModule.php
index ed9ce4a40c21e87ec87d6aea163c9f385e721f5c..c52f8ee160113dbb573a089dad464ed5c4903707 100644
--- a/classes/modules/uriModule.php
+++ b/classes/modules/uriModule.php
@@ -11,27 +11,27 @@ class UriModule extends abstractModule{
   	global $endpoints;
   	global $lodspk;
   	
+  	if($conf['disableComponents'] == true){
+  	  return FALSE;
+  	}
   	require_once('classes/MetaDb.php');
   	$metaDb = new MetaDb($conf['metadata']['db']['location']);
-  	
   	$pair = Queries::getMetadata($localUri, $acceptContentType, $metaDb);
-  	
   	if($pair == NULL){ // Original URI is not in metadata
   	  if(Queries::uriExist($uri, $endpoints['local'])){
   	  	$page = Queries::createPage($uri, $localUri, $acceptContentType, $metaDb);
   	  	if($page == NULL){
-  	  	  Utils::send500("Can't write sqlite database.");
+  	  	  HTTPStatus::send500("Can't write sqlite database.");
   	  	}
-  	  	Utils::send303($page, $acceptContentType);
+  	  	HTTPStatus::send303($page, $acceptContentType);
   	  	exit(0);
   	  }else{
-  	  	return false; //Utils::send404($uri);
+  	  	return false;
   	  }
   	}
   	$extension = Utils::getExtension($pair[2]); 
   	$curie = Utils::uri2curie($pair[0]);
   	list($modelFile, $viewFile) = $this->getModelandView($curie, $extension);
-  	
   	if($modelFile == NULL){
   	  return FALSE;
   	}
@@ -63,7 +63,7 @@ class UriModule extends abstractModule{
   	
   	//If resource is not the page, send a 303 to the document
   	if($res == $localUri){
-  	  Utils::send303($page, $acceptContentType);
+  	  HTTPStatus::send303($page, $acceptContentType);
   	}
   	
   	$uri = $res;
@@ -86,35 +86,38 @@ class UriModule extends abstractModule{
   	//$lodspk = $conf['view']['standard'];
 
   	$lodspk['type'] = $modelFile;
+  	  	$lodspk['home'] = $conf['basedir'];
+
   	$lodspk['module'] = 'uri';
   	$lodspk['add_mirrored_uris'] = true;
   	$lodspk['this']['value'] = $uri;
   	$lodspk['this']['curie'] = Utils::uri2curie($uri);
   	$lodspk['local']['value'] = $localUri;
   	$lodspk['local']['curie'] = Utils::uri2curie($localUri);
-  	
-  	$lodspk['this']['contentType'] = $acceptContentType;
+  	$lodspk['contentType'] = $acceptContentType;
   	$lodspk['model'] = $conf['model']['directory'];
   	$lodspk['view'] = $conf['view']['directory'];
   	$lodspk['ns'] = $conf['ns'];
   	
   	
-  	chdir($conf['home'].$conf['model']['directory']);
+  	//chdir($conf['home'].$conf['model']['directory']);
   	Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
   	if(!$lodspk['resultRdf']){
   	  $results = Utils::internalize($results); 
-  	  $lodspk['firstResults'] = Utils::getfirstResultss($results);
+  	  $firstAux = Utils::getfirstResults($results);
   	  
   	  chdir($conf['home']);
   	  if(is_array($results)){
   	  	$resultsObj = Convert::array_to_object($results);
+  	  	$results = $resultsObj;
   	  }else{
   	  	$resultsObj = $results;
   	  }
+  	  $lodspk['firstResults'] = Convert::array_to_object($firstAux);
   	}else{
   	  $resultsObj = $results;
   	}
-  	chdir($conf['home']);
+  	//chdir($conf['home']);
   	if($conf['debug']){
   	  trigger_error("Using template ".$viewFile, E_USER_NOTICE);
   	  echo("TEMPLATE: ".$viewFile."\n\n");
@@ -126,14 +129,14 @@ class UriModule extends abstractModule{
   private static function getModelandView($uri, $extension){  	
   	global $conf;
   	global $lodspk;
-  	$auxViewFile  = $conf['view']['directory'].$conf['uri']['prefix'].$uri.'/'.$extension.'.template';
-  	$auxModelFile = $conf['model']['directory'].$conf['uri']['prefix'].$uri.'/'.$extension.'.queries';
- 	if(file_exists($auxModelFile)){
+  	$auxViewFile  = $conf['view']['directory'].'/'.$conf['uri']['prefix'].'/'.$uri.'/'.$extension.'.template';
+  	$auxModelFile = $conf['model']['directory'].'/'.$conf['uri']['prefix'].'/'.$uri.'/'.$extension.'.queries';
+  	if(file_exists($auxModelFile)){
  	  //Model exists
-  	  $modelFile = $conf['uri']['prefix'].$uri.'/'.$extension.'.queries';
+  	  $modelFile = $auxModelFile;//$conf['uri']['prefix'].$uri.'/'.$extension.'.queries';
   	  if(file_exists($auxViewFile) ){
   	  	//View exists, everything is fine
-  	  	$viewFile = $conf['uri']['prefix'].$uri.'/'.$extension.'.template';
+  	  	$viewFile = $conf['model']['directory'].'/'.$conf['uri']['prefix'].'/'.$uri.'/'.$extension.'.template';
   	  }elseif($extension != 'html'){
   	  	//View doesn't exists (and is not HTML)
   	  	$viewFile = null;  	  	
@@ -142,11 +145,11 @@ class UriModule extends abstractModule{
   	  	return array(null, null);
   	  }
   	  return array($modelFile, $viewFile);
-  	}elseif($extension != 'html' && file_exists($conf['model']['directory'].$conf['uri']['prefix'].$uri.'/html.queries')){
-  	  $modelFile = $conf['uri']['prefix'].$uri.'/html.queries';
-  	  if(file_exists($auxViewFile) ){
+  	}elseif(file_exists($conf['model']['directory'].'/'.$conf['uri']['prefix'].'/'.$uri.'/queries')){
+  	  $modelFile = $conf['model']['directory'].'/'.$conf['uri']['prefix'].'/'.$uri.'/queries';//$conf['uri']['prefix'].$uri.'/html.queries';
+	  if(file_exists($auxViewFile) ){
   	  	//View exists, everything is fine
-  	  	$viewFile = $conf['uri']['prefix'].$uri.'/'.$extension.'.template';
+  	  	$viewFile = $conf['model']['directory'].'/'.$conf['uri']['prefix'].'/'.$uri.'/'.$extension.'.template';
   	  }elseif($extension != 'html'){
   	  	//View doesn't exists (and is not HTML)
   	  	$lodspk['transform_select_query'] = true;
@@ -154,6 +157,7 @@ class UriModule extends abstractModule{
   	  }
   	  return array($modelFile, $viewFile);
   	}
+
   	return array(NULL, NULL);
   }
   
diff --git a/common.inc.php b/common.inc.php
index f7838ebe0871dd6d50457bef7cfd4b383163b4e1..95ea7bd75b1d8a7ba1c99c0ebc77def10f566827 100644
--- a/common.inc.php
+++ b/common.inc.php
@@ -1,5 +1,5 @@
 <?
-
+$conf['version'] = '20120411';
 $conf['output']['select'] = 'json';
 $conf['output']['describe'] = 'rdf';
 $conf['endpointParams']['config']['show_inline'] = 0;
@@ -12,15 +12,16 @@ $conf['metadata']['db']['location'] = 'meta/db.sqlite';
 
 include_once('namespaces.php');
 
-$conf['model']['directory'] = 'models/'; #include trailing slash!
+$conf['model']['directory'] = 'components'; #include trailing slash!
 $conf['model']['extension'] = '.model';
 $conf['model']['default'] = 'rdfs:Resource';
 
-$conf['view']['directory'] = 'views/'; #include trailing slash!
+$conf['view']['directory'] = 'components'; #include trailing slash!
 $conf['view']['extension'] = '.view';
 $conf['view']['default'] = 'rdfs:Resource';
 
 $conf['static']['directory'] = 'static/'; #include trailing slash!
+$conf['static']['haanga'] = false; //Should static files be processed by Haanga? 
 
 $conf['resource']['url_delimiter'] = "%u";
 
@@ -32,11 +33,10 @@ $conf['http_accept']['json'] = array('application/json', 'application/x-javascri
 $conf['http_accept']['nt']   = array('text/plain');
 
 
-$conf['service']['prefix'] = 'service.';
-$conf['service']['class'] = 'classes/BasicSpecialFunction.php';
+$conf['service']['prefix'] = 'services';
 
-$conf['type']['prefix'] = 'type.';
-$conf['uri']['prefix'] = 'uri.';
+$conf['type']['prefix'] = 'types';
+$conf['uri']['prefix'] = 'uris';
 
 //Frontpage when user goes to http://example.org/
 $conf['root'] = 'index.html';
@@ -60,10 +60,14 @@ $conf['modules'] = array();
 $conf['modules']['directory'] = 'classes/modules/';
 
 $conf['modules']['available'] = array('static','uri', 'type', 'service');
+<<<<<<< HEAD
 
 //Uncomment next line to enable sessions
 //$conf['modules']['available'] = array('session', 'static','uri', 'type', 'service');
 
+=======
+global $lodspk;
+>>>>>>> 190d4897be9d90712085169270a6e105600063f5
 include_once('settings.inc.php');
 $conf['view']['standard']['baseUrl'] = $conf['basedir'];
 ?>
diff --git a/doc/README b/doc/README
new file mode 100644
index 0000000000000000000000000000000000000000..604e9e250f7de569c346733ac8b68df994275f0f
--- /dev/null
+++ b/doc/README
@@ -0,0 +1,11 @@
+## Documentation
+
+The latest version of the documentation is available at 
+
+https://github.com/alangrafu/lodspeakr/wiki
+
+## Examples
+
+Some real-world examples are provided under example/components to show how components are used
+
+
diff --git a/doc/examples/components/services/people/html.template b/doc/examples/components/services/people/html.template
new file mode 100644
index 0000000000000000000000000000000000000000..f072a11adbc9b118fcc8e92705c29044eb6989d4
--- /dev/null
+++ b/doc/examples/components/services/people/html.template
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
+    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
+    {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
+  <head>
+    <title>TWC People directory</title>
+    <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
+  </head>
+  <body>
+    <h1>People</h1>
+	<ul>
+    {% for row in models.main %}
+        <li><a href="{{row.people.value}}">{{row.name.value}} - {{row.email.value}}</a></li>
+    {% endfor %}
+    </ul>
+  </body>
+</html>
diff --git a/doc/examples/components/services/people/queries/main.query b/doc/examples/components/services/people/queries/main.query
new file mode 100644
index 0000000000000000000000000000000000000000..3fcb2facef4a7f3dbbfe47002f5fc88280d99647
--- /dev/null
+++ b/doc/examples/components/services/people/queries/main.query
@@ -0,0 +1,10 @@
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+
+SELECT DISTINCT ?person ?email ?name WHERE {
+  GRAPH ?g {
+  	?person a foaf:Person ;
+  	        foaf:name ?name ;
+  			foaf:mbox ?email .
+  }
+}order by ?name
diff --git a/doc/examples/components/services/peopleByName/html.template b/doc/examples/components/services/peopleByName/html.template
new file mode 100644
index 0000000000000000000000000000000000000000..15462828d4dfa96b37a24866b3b2d18001b0b24b
--- /dev/null
+++ b/doc/examples/components/services/peopleByName/html.template
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
+    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
+    {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
+  <head>
+    <title>TWC People directory</title>
+    <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
+  </head>
+  <body>
+    <h1>People</h1>
+	<ul>
+    {% for row in models.main %}
+        <li><a href="{{row.person.value}}">{{row.name.value}} - {{row.email.value}}</a></li>
+    {% endfor %}
+    </ul>
+  </body>
+</html>
diff --git a/doc/examples/components/services/peopleByName/json.template b/doc/examples/components/services/peopleByName/json.template
new file mode 100644
index 0000000000000000000000000000000000000000..9aae302631b31bd5d7b6c42cdcdd6a445d4e1fe1
--- /dev/null
+++ b/doc/examples/components/services/peopleByName/json.template
@@ -0,0 +1,11 @@
+{
+  "people": [
+    {% for row in models.main %}
+        {
+          "uri": "{{row.person.value}}",
+          "name": "{{row.name.value}}",
+          "email": "{{row.email.value}}"
+        }{%if ! forloop.last%},{%endif%} 
+    {% endfor %}
+   ]
+}
diff --git a/doc/examples/components/services/peopleByName/queries/main.query b/doc/examples/components/services/peopleByName/queries/main.query
new file mode 100644
index 0000000000000000000000000000000000000000..e1d9d71e2b1aab631c65dcac6aa9772434eaf8b6
--- /dev/null
+++ b/doc/examples/components/services/peopleByName/queries/main.query
@@ -0,0 +1,11 @@
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+
+SELECT DISTINCT ?person ?email ?name WHERE {
+  GRAPH ?g {
+  	?person a foaf:Person ;
+  	        foaf:name ?name ;
+  			foaf:mbox ?email .
+     FILTER(regex(?name, "^{{lodspk.args.arg0}}", "i" ))
+  }
+}order by ?name
diff --git a/doc/examples/components/types/foaf:Person/html.template b/doc/examples/components/types/foaf:Person/html.template
new file mode 100644
index 0000000000000000000000000000000000000000..5d3b254b39f868aa5b0f4c26416c7ca163b49bec
--- /dev/null
+++ b/doc/examples/components/types/foaf:Person/html.template
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
+    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.0" xml:lang="en">
+  <head>
+    <title>Page about {{lodspk.this.value}}</title>
+    <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
+    <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version"   href="{{lodspk.this.value}}.rdf" />
+    <link rel="alternate" type="text/turtle"         title="Turtle Version"    href="{{lodspk.this.value}}.ttl" />
+    <link rel="alternate" type="text/plain"          title="N-Triples Version" href="{{lodspk.this.value}}.nt" />
+    <link rel="alternate" type="application/json"    title="RDFJSON Version"   href="{{lodspk.this.value}}.json" />
+  </head>
+  <body>
+    <img style='float:right;width:200px' src='{{first.personalDetails.pic.mirroredUri}}'/>
+    <h1>{{first.personalDetails.name.value}}</h1>
+    <p>{{first.personalDetails.desc.value}}
+    </p>
+  <div>
+    <h2>{{first.personalDetails.name.value}} has attended meetings with</h2>
+    <ul>
+    {% for row in models.attendees %}
+      <li><a href="{{row.attendee.value}}">{%if row.attendeeName.value%}{{row.attendeeName.value}}{%else%}{{row.attendee.curie}}{%endif%}</a></li>
+    {%endfor%}
+    </ul>
+  </div>
+  {%if first.dbpedia.bplace == null%}
+  <div>
+  {{first.dbpedia.birthplace.bplace.value}}
+  <h3>Born in: {{first.dbpedia.location.name.value}}</h3>
+  <div>
+  <div style="float:left">
+  </div><p style="float:left">{{first.dbpedia.location.abstract.value}}</p>
+  {{models.dbpedia.geo|googlemaps:"lat,lon,name"}}
+  </div>
+  {%endif%}
+  </div>
+  </body>
+</html>
diff --git a/doc/examples/components/types/foaf:Person/queries/attendees.query b/doc/examples/components/types/foaf:Person/queries/attendees.query
new file mode 100644
index 0000000000000000000000000000000000000000..19b4390df2b7e799b9112005078598f670bcc1a5
--- /dev/null
+++ b/doc/examples/components/types/foaf:Person/queries/attendees.query
@@ -0,0 +1,12 @@
+PREFIX twc: <http://tw.rpi.edu/schema/>
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+SELECT DISTINCT ?attendee ?attendeeName  WHERE {
+  GRAPH <http://tw.rpi.edu:2020/books>{
+    ?event twc:hasAttendee <{{uri}}> .
+    ?event twc:hasAttendee ?attendee .    
+    OPTIONAL{ 
+      ?attendee foaf:name ?attendeeName .
+    }
+    FILTER(str(?attendee) != "{{uri}}")
+  }
+}
diff --git a/doc/examples/components/types/foaf:Person/queries/birthplace.query b/doc/examples/components/types/foaf:Person/queries/birthplace.query
new file mode 100644
index 0000000000000000000000000000000000000000..526417f818b393b9862e72114ccc37cf2aa053ae
--- /dev/null
+++ b/doc/examples/components/types/foaf:Person/queries/birthplace.query
@@ -0,0 +1,8 @@
+PREFIX twc: <http://tw.rpi.edu/schema/>
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX dbp: <http://dbpedia.org/ontology/>
+SELECT distinct ?bplace  WHERE {
+  GRAPH <http://tw.rpi.edu:2020/books>{
+  	<{{uri}}> dbp:birthPlace ?bplace
+  }
+}
diff --git a/doc/examples/components/types/foaf:Person/queries/endpoint.dbpedia/geo.query b/doc/examples/components/types/foaf:Person/queries/endpoint.dbpedia/geo.query
new file mode 100644
index 0000000000000000000000000000000000000000..b895676dfce2274fb5c72aa6bfeec3c08b92e7ba
--- /dev/null
+++ b/doc/examples/components/types/foaf:Person/queries/endpoint.dbpedia/geo.query
@@ -0,0 +1,9 @@
+PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
+PREFIX dbp: <http://dbpedia.org/ontology/>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+
+SELECT distinct ?lat ?lon ?name WHERE {
+<{{first.birthplace.bplace.value}}> rdfs:label ?name ;
+				    geo:lat  ?lat;
+                                    geo:long ?lon.
+}limit 1
diff --git a/doc/examples/components/types/foaf:Person/queries/endpoint.dbpedia/location.query b/doc/examples/components/types/foaf:Person/queries/endpoint.dbpedia/location.query
new file mode 100644
index 0000000000000000000000000000000000000000..f76659a1fb37ab95c8122f02f58f1cd1138e3f29
--- /dev/null
+++ b/doc/examples/components/types/foaf:Person/queries/endpoint.dbpedia/location.query
@@ -0,0 +1,7 @@
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+PREFIX dbp: <http://dbpedia.org/ontology/>
+SELECT distinct ?name ?abstract  WHERE {
+<{{first.birthplace.bplace.value}}> dbp:abstract ?abstract;
+rdfs:label ?name .
+FILTER(lang(?abstract) = "en")
+}limit 1
diff --git a/doc/examples/components/types/foaf:Person/queries/main.query b/doc/examples/components/types/foaf:Person/queries/main.query
new file mode 100644
index 0000000000000000000000000000000000000000..1b878b6252b6b7e96102e4f754f272c5a748b662
--- /dev/null
+++ b/doc/examples/components/types/foaf:Person/queries/main.query
@@ -0,0 +1,10 @@
+PREFIX twc: <http://tw.rpi.edu/schema/>
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+SELECT ?event ?eventName  WHERE {
+  GRAPH <http://tw.rpi.edu:2020/books>{
+    ?event twc:hasAttendee <{{uri}}> .
+    OPTIONAL{ 
+      ?event foaf:name ?eventName .
+    }
+  }
+}
diff --git a/doc/examples/components/types/foaf:Person/queries/personalDetails.query b/doc/examples/components/types/foaf:Person/queries/personalDetails.query
new file mode 100644
index 0000000000000000000000000000000000000000..cf35f1607a9c5daa4915a9b9bf282c8ad1419500
--- /dev/null
+++ b/doc/examples/components/types/foaf:Person/queries/personalDetails.query
@@ -0,0 +1,12 @@
+PREFIX twc: <http://tw.rpi.edu/schema/>
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+PREFIX dcterms: <http://purl.org/dc/terms/>
+
+SELECT ?name ?desc ?pic WHERE {
+  GRAPH <http://tw.rpi.edu:2020/books>{
+     <{{uri}}> foaf:name ?name ;
+     		   foaf:depiction ?pic ;
+               dcterms:description ?desc.
+  }
+}
diff --git a/views/header.inc b/doc/examples/originalComponents/includes/header.inc
similarity index 100%
rename from views/header.inc
rename to doc/examples/originalComponents/includes/header.inc
diff --git a/views/service.classes/html.template b/doc/examples/originalComponents/services/classes/html.template
similarity index 89%
rename from views/service.classes/html.template
rename to doc/examples/originalComponents/services/classes/html.template
index 3c75a1c865f4f8252068bfc661900169f1ad498f..0e9d4bcf44e7783ea2005e075e974d711450d890 100644
--- a/views/service.classes/html.template
+++ b/doc/examples/originalComponents/services/classes/html.template
@@ -4,12 +4,12 @@
     <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
     {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
   <head>
-    <title>My new Service</title>
+    <title>Classes available</title>
     <link href="css/basic.css" rel="stylesheet" type="text/css" media="screen" />
   </head>
   <body>
     <h1>Classes available</h1>
-{%include "../header.inc"%}
+{%include "../../includes/header.inc"%}
 	<ul>
     {% for row in models.main %}
         <li><a href="{{lodspk.baseUrl}}instances/{{ row.resource.curie }}">{{row.resource.curie}}</a></li>
diff --git a/models/service.classes/html.queries/main.query b/doc/examples/originalComponents/services/classes/queries/main.query
similarity index 100%
rename from models/service.classes/html.queries/main.query
rename to doc/examples/originalComponents/services/classes/queries/main.query
diff --git a/models/service.instances/html.queries/main.query b/doc/examples/originalComponents/services/instances/html.queries/main.query
similarity index 100%
rename from models/service.instances/html.queries/main.query
rename to doc/examples/originalComponents/services/instances/html.queries/main.query
diff --git a/views/service.instances/html.template b/doc/examples/originalComponents/services/instances/html.template
similarity index 80%
rename from views/service.instances/html.template
rename to doc/examples/originalComponents/services/instances/html.template
index c4b5de63882277515e3df3223f9a5dd5e8b7524f..d9bf5b429fc01622699f35a82949e368d8a856a9 100644
--- a/views/service.instances/html.template
+++ b/doc/examples/originalComponents/services/instances/html.template
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
     "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
-    <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" 
+    <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
     {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
   <head>
     <title>Instances of {{lodspk.args.arg0}}</title>
@@ -9,7 +9,7 @@
   </head>
   <body>
     <h1>Instances of class {{lodspk.args.arg0}}</h1>
-{%include "../header.inc"%}
+{%include "../../includes/header.inc"%}
 	<ul>
     {% for row in models.main %}
         <li><a href="{{ row.resource.value }}">{{row.resource.curie}}</a></li>
diff --git a/views/service.namedGraphs/html.template b/doc/examples/originalComponents/services/namedGraphs/html.template
similarity index 78%
rename from views/service.namedGraphs/html.template
rename to doc/examples/originalComponents/services/namedGraphs/html.template
index 1df5c5d4124b3a8a4fb86774acf38a31e52755d7..f1c287312a104708130948cd3c0f6832a5b23efe 100644
--- a/views/service.namedGraphs/html.template
+++ b/doc/examples/originalComponents/services/namedGraphs/html.template
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
     "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
-    <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" 
+    <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
     {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
   <head>
     <title>Named Graphs</title>
@@ -9,7 +9,7 @@
   </head>
   <body>
     <h1>Named graphs available</h1>
-{%include "../header.inc"%}
+{%include "../../includes/header.inc"%}
 	<ul>
     {% for row in models.main %}
         <li>{{row.g.value}}</li>
diff --git a/models/service.namedGraphs/html.queries/main.query b/doc/examples/originalComponents/services/namedGraphs/queries/main.query
similarity index 100%
rename from models/service.namedGraphs/html.queries/main.query
rename to doc/examples/originalComponents/services/namedGraphs/queries/main.query
diff --git a/doc/examples/originalComponents/types/rdfs:Resource/html.template b/doc/examples/originalComponents/types/rdfs:Resource/html.template
new file mode 100644
index 0000000000000000000000000000000000000000..7dd111f2894fb9e1a62d9879d82c23e18690716a
--- /dev/null
+++ b/doc/examples/originalComponents/types/rdfs:Resource/html.template
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
+    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
+    <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
+    {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
+    <head>
+    <title>Page about {{lodspk.this.value}}</title>
+    <link href="{{lodspk.home}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
+    <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{lodspk.this.value}}.rdf" />
+    <link rel="alternate" type="text/turtle" title="Turtle Version" href="{{lodspk.this.value}}.ttl" />
+    <link rel="alternate" type="text/plain" title="N-Triples Version" href="{{lodspk.this.value}}.nt" />
+    <link rel="alternate" type="application/json" title="RDFJSON Version" href="{{lodspk.this.value}}.json" />
+  </head>
+  <body about="{{lodspk.this.value}}">
+    <h1>Default view</h1>
+
+    <div style='margin-top: 40px'>
+    <table>
+    <tr><th>Subject</th><th>Predicate</th><th>Object</th></tr>
+    {% for row in models.po %}
+     <tr>
+<td>{%if forloop.first%}<a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a>{%endif%}</td>
+     <td style='background-color:#c9f9c9'><a href='{{row.p.value}}'>{{row.p.curie}}</a></td>
+     
+        <td style='background-color:#c9f9c9'>
+        {%if row.o.uri == 1%}
+        <a rev='[{{row.p.curie}}]' href='{{row.o.value}}'>{{row.o.curie}}</a>
+        {%else%}
+        {{row.o.value}}
+        {%endif%}
+        </td>
+
+        </tr>
+    {% endfor %}
+<tr><td></td><td><a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></td><td></td></tr>
+
+    {% for row in models.sp %}
+      <tr>
+        <td style='background-color:#c9f9c9'><a href='{{row.s.value}}'>{{row.s.curie}}</a></td>
+
+        <td style='background-color:#c9f9c9'><a rel='{{row.s.curie}}' href='{{row.p.value}}'>{{row.p.curie}}</a></td>
+<td>{%if forloop.first%}<a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a>{%endif%}</td>
+        </tr>
+    {% endfor %}
+    <tr><th>Subject</th><th>Predicate</th><th>Object</th></tr>
+
+    </table>
+    </div>    
+    
+    <br/>
+  </body>
+</html>
diff --git a/doc/examples/originalComponents/types/rdfs:Resource/queries/po.query b/doc/examples/originalComponents/types/rdfs:Resource/queries/po.query
new file mode 100644
index 0000000000000000000000000000000000000000..f573aab3fcafc3c5e00ee35cea1f50dcb8bb1598
--- /dev/null
+++ b/doc/examples/originalComponents/types/rdfs:Resource/queries/po.query
@@ -0,0 +1,9 @@
+SELECT ?p ?o  WHERE {
+  {
+    GRAPH ?g{
+                <{{uri}}> ?p ?o.
+    }
+  }UNION{     
+                <{{uri}}> ?p ?o .
+  }
+}
diff --git a/doc/examples/originalComponents/types/rdfs:Resource/queries/sp.query b/doc/examples/originalComponents/types/rdfs:Resource/queries/sp.query
new file mode 100644
index 0000000000000000000000000000000000000000..3b5b69fb13293b740abd2407957cad96b2f9866f
--- /dev/null
+++ b/doc/examples/originalComponents/types/rdfs:Resource/queries/sp.query
@@ -0,0 +1,9 @@
+SELECT ?s ?p  WHERE {
+  {
+    GRAPH ?g{
+                ?s ?p <{{uri}}> .
+    }
+  }UNION{     
+                ?s ?p <{{uri}}> .
+  }
+}
diff --git a/index.php b/index.php
index 264c9ffa25ce0b1fdefc1865a3a4827da5de13ab..d9bdc51592e1fdf9cbc6b07446cd976e31e4b557 100755
--- a/index.php
+++ b/index.php
@@ -22,6 +22,7 @@ if($conf['debug']){
   error_reporting(E_ERROR);
 }
 
+include_once('classes/HTTPStatus.php');
 include_once('classes/Utils.php');
 include_once('classes/Queries.php');
 include_once('classes/Endpoint.php');
@@ -37,7 +38,7 @@ $extension = Utils::getExtension($acceptContentType);
 
 //Check content type is supported by LODSPeaKr
 if($acceptContentType == NULL){
-  Utils::send406($uri);
+  HTTPStatus::send406($uri);
 }
 
 //Export
@@ -67,7 +68,7 @@ if(isset($conf['mirror_external_uris']) && $conf['mirror_external_uris'] != fals
   }elseif(is_string($conf['mirror_external_uris'])){
   	$uri = $conf['mirror_external_uris'].$_GET['q'];
   }else{
-  	Utils::send500("Error in mirroring configuration");
+  	HTTPStatus::send500("Error in mirroring configuration");
   	exit(1);
   }
   
@@ -79,17 +80,17 @@ foreach($conf['modules']['available'] as $i){
   $className = $i.'Module';
   $currentModule = $conf['modules']['directory'].$className.'.php';
   if(!is_file($currentModule)){
-  	Utils::send500("<br/>Can't load or error in module <tt>".$currentModule."</tt>" );
+  	HTTPStatus::send500("<br/>Can't load or error in module <tt>".$currentModule."</tt>" );
   	exit(1);
   }
   require_once($currentModule);
   $module = new $className();
-  $matching = $module->match($uri) ;
+  $matching = $module->match($uri);
   if($matching != FALSE){
   	$module->execute($matching);
   	exit(0);
   }
 }
 
-Utils::send404($uri);
+HTTPStatus::send404($uri);
 ?>
diff --git a/install.sh b/install.sh
index 1c142215d16706d26998360ec2fe25c53d8ed8a0..ff5d410dfa028b0ffd5a025770af4829a081aedd 100755
--- a/install.sh
+++ b/install.sh
@@ -1,16 +1,14 @@
 #!/usr/bin/env bash
 #
-#
-
 root_htaccess="root.htaccess"
 parent_htaccess="../.htaccess"
 settings_file="settings.inc.php"
 
 metadb="db.sqlite"
-basedir="http://localhost/my/data/"
+basedir="http://localhost/my/data"
 home=`basename \`pwd\`` # 'lodspeakr', the directory from git clone
 ns=$basedir
-endpoint="http://localhost/sparql?"
+endpoint="http://localhost/sparql"
 everything_ok="n"
 
 if [ -e "$parent_htaccess" ]; then
@@ -45,6 +43,7 @@ while [ "$everything_ok" != "y" ]; do
   read -u 1 aux_ns
   echo ""
   if [ "$aux_ns" != "" ]; then
+    aux_ns="`echo $aux_ns | sed 's/\/$//'`/" # remove any ending slash and append one.
     ns=$aux_ns
   fi
 
@@ -53,7 +52,7 @@ while [ "$everything_ok" != "y" ]; do
   if [[ "$basedir" =~ ^"$ns" ]]; then
     external="false"
   else
-    external=$ns
+    external="\$conf['ns']['local']"
     extra="\$conf['ns']['base']   = '$basedir';"
   fi
   
@@ -94,7 +93,6 @@ LODSPEAKR_HOME=`pwd`/
 \$conf['home'] = '$LODSPEAKR_HOME';
 \$conf['basedir'] = '$basedir';
 \$conf['debug'] = false;
-\$conf['mirror_external_uris'] = '$external';
 
 /*ATTENTION: By default this application is available to
  * be exported and copied (its configuration)
@@ -106,6 +104,8 @@ LODSPEAKR_HOME=`pwd`/
 #If you want to add/overrid a namespace, add it here
 \$conf['ns']['local']   = '$ns';
 $extra
+
+\$conf['mirror_external_uris'] = $external;
 ?>" 
 echo "$content" > $settings_file
 chmod 644 $settings_file
@@ -113,21 +113,34 @@ echo "Created new configuration file: $settings_file"
 echo ""
 echo "WARNING: Copying $root_htaccess as .htaccess in parent directory"
 echo ""
-cp $root_htaccess $parent_htaccess
-
+echo "RewriteEngine on" > $parent_htaccess
+echo >> $parent_htaccess
+echo "RewriteRule ^\$ $1/index.php [L]" >> $parent_htaccess
+cat $root_htaccess >> $parent_htaccess
+echo "RewriteRule ^(.+)\$ $1/index.php?q=\$1 [L]" >> $parent_htaccess
 mkdir cache
-
+cp -r doc/examples/originalComponents components
+mkdir -p components/uris
+bold=`tput bold`
+normal=`tput sgr0`
 echo
 echo "                                      *** ATTENTION ***"
 echo
-echo "LODSPeaKr needs the web server to have write permissions for lodspeakr/cache/ and lodspeakr/meta/."
+echo "LODSPeaKr needs the web server to have write permissions for $1/cache/ and $1/meta/."
 echo
 echo
 echo "Common ways of doing this:"
-echo " chown -R www-apache lodspeakr/cache lodspeakr/meta (find the name of the apache user in your system)"
-echo " chmod -R g+w lodspeakr/cache lodspeakr/meta (if you have a group in common with the apache user)"
-echo " chmod -R 777 lodspeakr/cache lodspeakr/meta (highly discouraged but useful to test when everything fails. It shouldn't be used in production sites)"
+echo " ${bold}chown -R www-apache $1/cache $1/meta${normal} (find the name of the apache user in your system)"
+echo " ${bold}chown -R apache $1/cache $1/meta${normal} (find the name of the apache user in your system)"
+echo " ${bold}chown -R www-data $1/cache $1/meta${normal} (find the name of the apache user in your system)"
+echo " ${bold}chmod -R g+w $1/cache $1/meta${normal} (if you have a group in common with the apache user)"
+echo " ${bold}chmod -R 777 $1/cache $1/meta${normal} (highly discouraged but useful to test when everything fails. It shouldn't be used in production sites)"
 echo
 echo "Please give the server write permissions. Otherwise, LODSPeaKr will not work."
 echo
-echo "You can now visit $basedir to navigate through your data."
+echo
+echo
+echo "--------------------------------------------------------------------------------------------------------"
+echo "You can now visit ${bold}$basedir${normal} to navigate through your data."
+echo "--------------------------------------------------------------------------------------------------------"
+echo
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Date.php b/lib/Haanga/lib/Haanga/Extension/Filter/Date.php
index b60b299e17a592dff1ca31d6dd9049961b53848b..b15bdc981df8815d764c2961081f4a638865ee7c 100644
--- a/lib/Haanga/lib/Haanga/Extension/Filter/Date.php
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Date.php
@@ -4,7 +4,8 @@ class Haanga_Extension_Filter_Date
 {
     static function generator($compiler, $args)
     {
-        return hexec('date', $args[1], $args[0]);
+//        return hexec( 'date', $args[1], hexec('strtotime', $args[1]));
+        return hexec('date', $args[1], hexec('strtotime', $args[0]));
     }
 }
     
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Deurifier.php b/lib/Haanga/lib/Haanga/Extension/Filter/Deurifier.php
new file mode 100644
index 0000000000000000000000000000000000000000..767bc8c3ec74ac3b8501d5cc64e0ceb7ae831fc4
--- /dev/null
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Deurifier.php
@@ -0,0 +1,14 @@
+<?php
+
+class Haanga_Extension_Filter_Deurifier
+{
+  static function main($uri)
+  {
+    $newUri = preg_replace('/^http\//', 'http://', $uri);
+    $newUri = preg_replace('/__hash__/', '#', $newUri);
+    $newUri = preg_replace('/__qmark__/', '?', $newUri);
+    return $newUri;
+  }
+}
+
+
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Explode.php b/lib/Haanga/lib/Haanga/Extension/Filter/Explode.php
new file mode 100644
index 0000000000000000000000000000000000000000..7e6deae3c607a0bf519281e00e71abd01867bc9c
--- /dev/null
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Explode.php
@@ -0,0 +1,13 @@
+<?php
+
+class Haanga_Extension_Filter_Explode
+{
+    static function generator($compiler, $args)
+    {
+        if (count($args) != 2) {
+            $compiler->Error("Explode only needs two parameter");
+        }
+
+        return hexec('explode', $args[1], $args[0]);
+    }
+}
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Googlemaps.php b/lib/Haanga/lib/Haanga/Extension/Filter/Googlemaps.php
index 08faea9a6a61aa1480aac9554db0007bcf0a06ab..36e7b6ea28038015abf029e0ffa9fc4e37a601ad 100644
--- a/lib/Haanga/lib/Haanga/Extension/Filter/Googlemaps.php
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Googlemaps.php
@@ -50,6 +50,7 @@ class Haanga_Extension_Filter_Googlemaps{
   	$pre = "<div id='map_canvas_".$randId."' style='width: ".$w."px; height: ".$h."px'></div><script type='text/javascript'
   	src='http://maps.googleapis.com/maps/api/js?sensor=false'></script>
     <script type='text/javascript'>
+    //<![CDATA[
     function initialize() {
 	  var myOptions = {
 	  zoom: 4,
@@ -88,6 +89,7 @@ class Haanga_Extension_Filter_Googlemaps{
     }
         
     google.maps.event.addDomListener(window, 'load', initialize);
+    //]]>
     </script>";
     return $pre;
   }
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Length.php b/lib/Haanga/lib/Haanga/Extension/Filter/Length.php
index d0fb526222eff1a0a67b739bfb575686a093a222..952f377c66ac47f9d330b95cdb92584421c00171 100644
--- a/lib/Haanga/lib/Haanga/Extension/Filter/Length.php
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Length.php
@@ -7,6 +7,7 @@ class Haanga_Extension_Filter_Length
     {
         $count  = hexec('count', $args[0]);
         $strlen = hexec('strlen', $args[0]);
+        $vars   = hexec('count', hexec('get_object_vars', $args[0]));
         $guess  = hexpr_cond(hexec('is_array', $args[0]), hexec('count', $args[0]),
                             hexec('strlen', $args[0]));
 
@@ -18,8 +19,10 @@ class Haanga_Extension_Filter_Length
                 return $count;
             } else if  (is_string($value)) {
                 return $strlen;
+            } else if  (is_object($value)) {
+                return $vars;
             } else {
-                return $guess;
+                return $gess;
             }
         }
 
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Pop.php b/lib/Haanga/lib/Haanga/Extension/Filter/Pop.php
new file mode 100644
index 0000000000000000000000000000000000000000..5d3914a415d0ed10eded2a564030ccb15d786581
--- /dev/null
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Pop.php
@@ -0,0 +1,13 @@
+<?php
+
+class Haanga_Extension_Filter_Pop
+{
+    static function generator($compiler, $args)
+    {
+        if (count($args) != 1) {
+            $compiler->Error("Pop only needs two parameter");
+        }
+
+        return hexec('array_pop', $args[0]);
+    }
+}
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Urifier.php b/lib/Haanga/lib/Haanga/Extension/Filter/Urifier.php
new file mode 100644
index 0000000000000000000000000000000000000000..b917b9a4b6031c283d897bef17d03ead3030586a
--- /dev/null
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Urifier.php
@@ -0,0 +1,14 @@
+<?php
+
+class Haanga_Extension_Filter_Urifier
+{
+  static function main($uri)
+  {
+    $newUri = preg_replace('/^http:\/\//', 'http/', $uri);
+    $newUri = preg_replace('/#/', '__hash__', $newUri);
+    $newUri = preg_replace('/\?/', '__qmark__', $newUri);
+    return $newUri;
+  }
+}
+
+
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Urifragment.php b/lib/Haanga/lib/Haanga/Extension/Filter/Urifragment.php
new file mode 100644
index 0000000000000000000000000000000000000000..d84b3f152cbfc1cff040ccdc6fcaca9f65800c82
--- /dev/null
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Urifragment.php
@@ -0,0 +1,9 @@
+<?php
+
+class Haanga_Extension_Filter_Urifragment
+{
+   static function generator($cmp, $args)
+    {
+        return hexec('parse_url', $args[0], hconst('PHP_URL_FRAGMENT'));
+    }
+}
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Uripath.php b/lib/Haanga/lib/Haanga/Extension/Filter/Uripath.php
new file mode 100644
index 0000000000000000000000000000000000000000..1de855ab2bc46ae82f823d72f14c89826de9c9f3
--- /dev/null
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Uripath.php
@@ -0,0 +1,9 @@
+<?php
+
+class Haanga_Extension_Filter_Uripath
+{
+    static function generator($cmp, $args)
+    {
+        return hexec('parse_url', $args[0], hconst('PHP_URL_PATH'));
+    }
+}
diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Urischeme.php b/lib/Haanga/lib/Haanga/Extension/Filter/Urischeme.php
new file mode 100644
index 0000000000000000000000000000000000000000..2fc5457f344c1fd4d065de4a9d183989af397c43
--- /dev/null
+++ b/lib/Haanga/lib/Haanga/Extension/Filter/Urischeme.php
@@ -0,0 +1,9 @@
+<?php
+
+class Haanga_Extension_Filter_Urischeme
+{
+    static function generator($cmp, $args)
+    {
+        return hexec('parse_url', $args[0], hconst('PHP_URL_SCHEME'));
+    }
+}
diff --git a/lib/Haanga/lib/Haanga/Extension/Tag/Escape.php b/lib/Haanga/lib/Haanga/Extension/Tag/Escape.php
new file mode 100644
index 0000000000000000000000000000000000000000..e4e4a0107114a8a25c7d6ab33abaa7fe5093fe4d
--- /dev/null
+++ b/lib/Haanga/lib/Haanga/Extension/Tag/Escape.php
@@ -0,0 +1,7 @@
+<?php
+
+class Haanga_Extension_Tag_Escape
+{
+  public static $is_block  = TRUE;
+  public $php_alias = "htmlspecialchars";
+}
diff --git a/models/type.rdfs:Resource/html.queries/main.query b/models/type.rdfs:Resource/html.queries/main.query
deleted file mode 100644
index 2f315c7c5e89f64ea6ed61f19505e523b64b03d0..0000000000000000000000000000000000000000
--- a/models/type.rdfs:Resource/html.queries/main.query
+++ /dev/null
@@ -1,18 +0,0 @@
-SELECT ?s2 ?p2 ?s1 ?p1  WHERE {
-{
-GRAPH ?g{
-        {
-                <{{uri}}> ?s1 ?p1 .
-        }UNION{
-                ?s2 ?p2 <{{uri}}> .
-
-        }
-}
-}UNION{        {
-                <{{uri}}> ?s1 ?p1 .
-        }UNION{
-                ?s2 ?p2 <{{uri}}> .
-
-        }
-}
-}
diff --git a/root.htaccess b/root.htaccess
index d782c9601bc2287282286705ecd267916a2c11cc..bee4ad3061cadaba0f7d5949ca3135a587c3a120 100644
--- a/root.htaccess
+++ b/root.htaccess
@@ -5,4 +5,4 @@ RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{SCRIPT_FILENAME} !.*/index.php$
 
-RewriteRule ^(.+)$ lodspeakr/index.php?q=$1 [L]
+
diff --git a/static/css/basic.css b/static/css/basic.css
index b44283a4e162b4c1cd7e190715db34c01af35cd9..bf25c462d592cd9e593ff5004236369a5912f2db 100644
--- a/static/css/basic.css
+++ b/static/css/basic.css
@@ -3,7 +3,7 @@ body {
 }
 
 h1{
-  font-size: 45px;
+  font-size: 24px;
 }
 
 h1,h2,body {
@@ -29,15 +29,14 @@ a:hover{
 
 
 table tr td {
-    border-width: thin;
 	padding: 2px;
-	border-style: dotted;
 	border-color: gray;
 	background-color: white;
 }
-
+td{
+  max-width:550px;
+  word-wrap: break-word;
+}
 table{
   width: 50%;
-  margin-left:100px;
-  margin-right:auto;
 }
diff --git a/utils/create_db.sh b/utils/create_db.sh
index 285062c2c4a538399e2bde10b7a66bf33006b6df..f0226b38b568f43b1f318d12676d945d028131b5 100755
--- a/utils/create_db.sh
+++ b/utils/create_db.sh
@@ -14,6 +14,9 @@ if [ ! -e $1 ]; then
   	exit 1
   fi
   $SQLITE3 $1 'CREATE TABLE document (uri varcharg(1000), doc varchar(1000), format varchar(50));'
+  $SQLITE3 $1 'CREATE INDEX IF NOT EXISTS document_uri ON document(uri);'
+  $SQLITE3 $1 'CREATE INDEX IF NOT EXISTS document_uri_format ON document(uri, format);'
+  $SQLITE3 $1 'CREATE INDEX IF NOT EXISTS document_doc ON document(doc);'
 else
   echo "WARNING: SQLite database already exists."
 fi
diff --git a/utils/install b/utils/install
index 29935f55980c9422e4f73ee8790ad5cfe2373b9c..c0bd38ef5aacbd057e281ab1498a23a9bdb404c8 100644
--- a/utils/install
+++ b/utils/install
@@ -1,7 +1,12 @@
 #!/usr/bin/env bash
+#
 # Installation script for LODSPeaKr (http://lodspeakr.org)
 # Author: Alvaro Graves (alvaro@graves.cl)
 # Modified by: Tim Lebo (lebot@rpi.edu)
+#
+# The URL:
+#    http://lodspeakr.org/install 
+#       303 redirects to this script.
 
 lodspeakr_repository="git://github.com/alangrafu/lodspeakr.git"
 home=`basename $lodspeakr_repository | sed 's/.git//'`
@@ -17,7 +22,7 @@ fi
 if [ ! -e "$home" ]; then
    $GIT clone $lodspeakr_repository
    cd $home
-   ./install.sh
-else
+   ./install.sh $home
+ else
    echo "There is already an existing directory called '$home'. Installation cancelled. Remove it first and try again."
 fi
diff --git a/utils/install-dev b/utils/install-dev
new file mode 100644
index 0000000000000000000000000000000000000000..51c534c66100177a3d6de6a84e14350f123c2f85
--- /dev/null
+++ b/utils/install-dev
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+#
+# Installation script for LODSPeaKr (http://lodspeakr.org)
+# Author: Alvaro Graves (alvaro@graves.cl)
+# Modified by: Tim Lebo (lebot@rpi.edu)
+#
+# The URL:
+#    http://lodspeakr.org/install 
+#       303 redirects to this script.
+
+lodspeakr_dir="lodspeakr"
+lodspeakr_repository="git@github.com:alangrafu/lodspeakr.git" # NOTE: the rest of this file should be identical to file 'install'
+home=`basename $lodspeakr_repository | sed 's/.git//'`
+
+source ~/.bashrc
+GIT=`which git`
+
+if [ -z "$GIT" ]; then
+  echo "git is required to continue installation. Please add git to your \$PATH."
+  exit 1
+fi
+
+if [ ! -e "$home" ]; then
+   $GIT clone $lodspeakr_repository
+   cd $home
+   ./install.sh $lodspeakr_dir
+ else
+   echo "There is already an existing directory called '$home'. Installation cancelled. Remove it first and try again."
+fi
diff --git a/utils/lodspk.sh b/utils/lodspk.sh
index b97a987691bd9e3dac5d8e86ec2255e2f17b7be8..3d64011929446ea00125f3de2b43615434a6f2c8 100755
--- a/utils/lodspk.sh
+++ b/utils/lodspk.sh
@@ -1,33 +1,43 @@
 #!/bin/bash
 #
 # https://github.com/alangrafu/lodspeakr/blob/master/utils/ldspk.sh
-USAGE="Usage: $0 create|delete uri|type|service foo [html|rdf|ttl|nt|json]"
+USAGE="Usage:\n"
+USAGE=$USAGE" Create component:\t\t\t\t\t$0 create uri|type|service foo [html|rdf|ttl|nt|json]\n"
+USAGE=$USAGE" Delete component:\t\t\t\t\t$0 delete uri|type|service foo [html|rdf|ttl|nt|json]\n"
+USAGE=$USAGE" Turn debug:\t\t\t\t\t\t$0 debug on|off\n"
+USAGE=$USAGE" Switch to standard view/models temporaly:\t\t$0 disable on|off\n"
+USAGE=$USAGE" Backup current installation:\t\t\t\t$0 backup\n"
+USAGE=$USAGE" Restore previous installation:\t\t\t\t$0 restore\n"
+USAGE=$USAGE" Clear cache:\t\t\t\t\t\t$0 cache clear\n"
+USAGE=$USAGE" Version:\t\t\t\t\t\t$0 version\n"
 USAGEDEBUG="Usage: $0 debug on|off"
 if [[ $# -eq 0 || "$1" == "--help" ]]; then
-  echo $USAGE
+  echo -e $USAGE
   exit 1
 fi
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-operations=( create delete debug backup restore )
+operations=( create delete debug backup restore disable cache version )
 currentOperation=
 
 if [[ ${operations[@]} =~ $1 ]]; then
   currentOperation=$1
 else
   echo "Operation \"$1\" not valid"
-  echo $USAGE
+  echo -e $USAGE
   exit 1
 fi
 
 ## Backup
 if [[ $currentOperation == "backup" ]]; then
   $DIR/modules/backup.sh
+  exit
 fi  
 
 ## Restore
 if [[ $currentOperation == "restore" ]]; then
   $DIR/modules/restore.sh
+  exit
 fi  
 
 ## Create/delete
@@ -40,7 +50,7 @@ if [[ $currentOperation == "create" ||  $currentOperation == "delete" ]]; then
     currentModule=$2
   else
     echo "Module \"$2\" not valid"
-    echo $USAGE
+    echo -e $USAGE
     exit 1
   fi
   
@@ -51,7 +61,7 @@ if [[ $currentOperation == "create" ||  $currentOperation == "delete" ]]; then
       currentFormat=$4
     else
       echo "Format \"$4\" not valid"
-      echo $USAGE
+      echo -e $USAGE
       exit 1
     fi
   else
@@ -71,8 +81,47 @@ if [[ $currentOperation == "debug" ]]; then
     debugOperation=$2
   else
     echo "Debug option not supported. Operation aborted" >&2
-    echo $USAGEDEBUG
+    echo -e $USAGE
     exit 1
   fi
   php $DIR/modules/debug.php "$debugOperation" 
+  $DIR/modules/cache.sh clear
+  exit
+fi
+
+## Disable
+if [[ $currentOperation == "disable" ]]; then
+ defaultOptions=( on off 0 1 )
+  defaultOperation=
+  if [[ ${defaultOptions[@]} =~ $2 ]]
+  then
+    defaultOperation=$2
+  else
+    echo "Disable option not supported. Operation aborted" >&2
+    echo -e $USAGE
+    exit 1
+  fi
+  php $DIR/modules/default.php "$defaultOperation" 
+  $DIR/modules/cache.sh clear
+  exit
+fi  
+
+## Cache
+if [[ $currentOperation == "cache" ]]; then
+  cacheOptions=( clear )
+  if [[ ${cacheOptions[@]} =~ $2 ]]
+  then
+    cacheOperation=$2
+  else
+    echo -e "Cache option not supported. Operation aborted\n" >&2
+    echo -e $USAGE
+    exit 1
+  fi
+  $DIR/modules/cache.sh $2
+  exit
+fi
+
+## Version
+if [[ $currentOperation == "version" ]]; then
+  $DIR/modules/version.sh
 fi
diff --git a/utils/modules/backup.sh b/utils/modules/backup.sh
index 7430c9af69b1e85740d6b5c9bc2b9fde754c564d..69bf5d24c4a186f5a714c9918d73e9429b2bac9e 100755
--- a/utils/modules/backup.sh
+++ b/utils/modules/backup.sh
@@ -19,7 +19,7 @@ fi
 
 tmpFile=$NAME"-backup-"`date +%Y%m%d%H%M%S`.tar.gz
 
-tar -czf $tmpFile settings.inc.php models views
+tar -czf $tmpFile settings.inc.php components
 
 mv $tmpFile $BACKUPDIR/
 echo "New backup $tmpFile created"
diff --git a/utils/modules/cache.sh b/utils/modules/cache.sh
new file mode 100755
index 0000000000000000000000000000000000000000..3cfa920f800738475ba91883e0f02dd4e8ddc5ce
--- /dev/null
+++ b/utils/modules/cache.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+cacheDir=$DIR/../../cache
+
+if [[ $1 == "clear" ]]; then
+  if [ -d "$cacheDir" ]; then
+    rm -f $cacheDir/*
+  else
+    echo "ERROR: Couldn't find cache directory" >&2 
+    exit 1
+  fi
+else
+    echo "ERROR: Invalid command" >&2 
+    exit 1  
+fi
diff --git a/utils/modules/create-service.sh b/utils/modules/create-service.sh
index cd29ce9fac0410c36697f20921af1945d43fe221..fbcbc581a49a90a0a7a283e9abbff4e18c6f64ea 100755
--- a/utils/modules/create-service.sh
+++ b/utils/modules/create-service.sh
@@ -2,32 +2,34 @@
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
-initToken='service'
+initToken='services'
 
 modelHtml=`cat  <<QUERY
 {%for h in base.header %}
 PREFIX {{h.prefix}}: <{{h.ns}}>
 {%endfor%}
 SELECT DISTINCT ?resource WHERE {
-  {%if base.args.arg0 %}GRAPH <{{lodspk.args.arg0}}>{ {%else%} GRAPH?g { {%endif%}
+  GRAPH {%if lodspk.args.arg0 %}<{{lodspk.args.arg0}}>{%else%}?g{%endif%} {
   	[] a ?resource .
-  {%if base.args.arg0 %} } {%endif%}
+  }
 }
+LIMIT 10
 QUERY`
 
 viewHtml=`cat  <<VIEW
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
-    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" 
-    {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" {%endfor%}
+      version="XHTML+RDFa 1.0" xml:lang="en">
   <head>
-    <title>My new Service</title>
+    <title>$1</title>
     <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
+    <style type="text/css">
+    </style>
   </head>
   <body>
-    <h1>Classes available</h1>
-	<ul>
+    <h1>$1</h1>
+ 	 <ul>
     {% for row in models.main %}
         <li><a href="{{lodspk.baseUrl}}special/instances/{{ row.resource.curie }}">{{row.resource.curie}}</a></li>
     {% endfor %}
@@ -36,85 +38,17 @@ viewHtml=`cat  <<VIEW
 </html>
 VIEW`
 
-modelRdf=`cat  <<QUERY
-DESCRIBE ?resource WHERE {
-  	[] a ?resource .
-}
-QUERY`
-
-viewRdf=`cat  <<QUERY
-{{r|safe}}
-QUERY`
-
-modelTtl=$modelRdf
-viewTtl=$viewRdf
-modelNt=$modelRdf
-viewNt=$viewRdf
-modelJson=$modelRdf
-viewJson=$viewJson
-
 #Check models
-mainModelDir=$DIR/../../models/$initToken.$1
+mainDir=$DIR/../../components/$initToken/$1/
 
-if [ -e "$mainModelDir" ]
+if [ -e "$mainDir" ]
 then
   echo "WARNING: At least one model for $1 exists." >&2
 else
-  mkdir $mainModelDir
-fi
-
-obj=( )
-if [ "$2" == "all" ]
-then
-  obj=( html rdf ttl nt json )
-else
-  obj=( $2 )
+  mkdir -p $mainDir/queries
 fi
 
-for i in ${obj[@]}
-do
-  if [ -e $mainModelDir/$i.queries ]
-  then
-    echo ERROR: $initToken.$1/$i.queries exists in models. Operation aborted >&2
-    exit 1
-  fi
-done
-
-
-#Check views
-mainViewDir=$DIR/../../views/$initToken.$1
-
-if [ -e "$mainViewDir" ]
-then
-  echo "WARNING: At least one view for $1 exists." >&2
-else
-  mkdir $mainViewDir
-fi
-
-
-for i in ${obj[@]}
-do
-  if [ -e $mainViewDir/$i.template ]
-  then
-    echo ERROR: $initToken.$1/$i already exist in views. Operation aborted >&2
-    exit 1
-  fi
-done
-
-
-#Create  file structure
-
-for i in ${obj[@]}
-do
-  mkdir $mainModelDir/$i.queries
-  if [ "$i" == "html" ]
-  then
-    echo "$modelHtml" > $mainModelDir/$i.queries/main.query
-    echo "$viewHtml" > $mainViewDir/$i.template
-  else
-    echo "$modelRdf" > $mainModelDir/$i.queries/main.query
-    echo "$viewRdf" > $mainViewDir/$i.template   
-  fi
-done
+echo -e "$modelHtml" > $mainDir/queries/main.query
+echo -e "$viewHtml" > $mainDir/html.template
 
 echo $initToken.$1 created/modified successfully! >&2
diff --git a/utils/modules/create-type.sh b/utils/modules/create-type.sh
index 0f9a552a6a2819f1134cc636e6323804e40892dd..379e2fe048ca3880addab878db4180274e1bc42f 100755
--- a/utils/modules/create-type.sh
+++ b/utils/modules/create-type.sh
@@ -2,24 +2,28 @@
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
-initToken='type'
+initToken='types'
 
-modelHtml=`cat <<QUERY
-SELECT ?s2 ?p2 ?s1 ?p1  WHERE {
+modelHtmlSP=`cat <<QUERY
+SELECT ?s ?p  WHERE {
   {
     GRAPH ?g{
-              {
-                <{{uri}}> ?s1 ?p1 .
-        }UNION{
-                ?s2 ?p2 <{{uri}}> .
-        }
+                ?s ?p <{{uri}}> .
     }
-  }UNION{
-        {
-                <{{uri}}> ?s1 ?p1 .
-        }UNION{
-                ?s2 ?p2 <{{uri}}> .
-        }
+  }UNION{     
+                ?s ?p <{{uri}}> .
+  }
+}
+QUERY`
+
+modelHtmlPO=`cat <<QUERY
+SELECT ?p ?o  WHERE {
+  {
+    GRAPH ?g{
+                <{{uri}}> ?p ?o.
+    }
+  }UNION{     
+                <{{uri}}> ?p ?o .
   }
 }
 QUERY`
@@ -29,136 +33,70 @@ viewHtml=`cat <<VIEW
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
     "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" 
+    <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
     {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
-  <head>
+    <head>
     <title>Page about {{lodspk.this.value}}</title>
-    <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
-    <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version"   href="{{lodspk.this.value}}.rdf" />
-    <link rel="alternate" type="text/turtle"         title="Turtle Version"    href="{{lodspk.this.value}}.ttl" />
-    <link rel="alternate" type="text/plain"          title="N-Triples Version" href="{{lodspk.this.value}}.nt" />
-    <link rel="alternate" type="application/json"    title="RDFJSON Version"   href="{{lodspk.this.value}}.json" />
+    <link href="{{lodspk.home}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
+    <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{lodspk.this.value}}.rdf" />
+    <link rel="alternate" type="text/turtle" title="Turtle Version" href="{{lodspk.this.value}}.ttl" />
+    <link rel="alternate" type="text/plain" title="N-Triples Version" href="{{lodspk.this.value}}.nt" />
+    <link rel="alternate" type="application/json" title="RDFJSON Version" href="{{lodspk.this.value}}.json" />
   </head>
   <body about="{{lodspk.this.value}}">
-    <h1>Page about <a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></h1>
-    <br/>
-    <h2>Class $1</h2>
-  <div>
-    <h2>Information from {{lodspk.this.curie}}</h2>
+    <h1>Default view</h1>
+
+    <div style='margin-top: 40px'>
     <table>
-    {% for row in models.main %}
+    <tr><th>Subject</th><th>Predicate</th><th>Object</th></tr>
+    {% for row in models.po %}
+     <tr>
+<td>{%if forloop.first%}<a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a>{%endif%}</td>
+     <td style='background-color:#c9f9c9'><a href='{{row.p.value}}'>{{row.p.curie}}</a></td>
+     
+        <td style='background-color:#c9f9c9'>
+        {%if row.o.uri == 1%}
+        <a rev='[{{row.p.curie}}]' href='{{row.o.value}}'>{{row.o.curie}}</a>
+        {%else%}
+        {{row.o.value}}
+        {%endif%}
+        </td>
 
-      {% if row.s1%}
-      <tr>
-        <td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td>
+        </tr>
+    {% endfor %}
+<tr><td></td><td><a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></td><td></td></tr>
 
-        {% if row.p1.uri == 1 %}
-        <td><a rel='{{row.s1.curie}}' href='{{row.p1.value}}'>{{row.p1.curie}}</a></td>
-        {% else %}
-        <td><span property='{{row.s1.curie}}'>{{row.p1.value}}</span></td>
-        {% endif %}
+    {% for row in models.sp %}
+      <tr>
+        <td style='background-color:#c9f9c9'><a href='{{row.s.value}}'>{{row.s.curie}}</a></td>
 
+        <td style='background-color:#c9f9c9'><a rel='{{row.s.curie}}' href='{{row.p.value}}'>{{row.p.curie}}</a></td>
+<td>{%if forloop.first%}<a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a>{%endif%}</td>
         </tr>
-      {% endif %}
     {% endfor %}
-    </table>
+    <tr><th>Subject</th><th>Predicate</th><th>Object</th></tr>
 
-    <br/><br/>
-    <h2>Information pointing to {{lodspk.this.curie}}</h2>
-    <table>
-    {% for row in models.main %}
-      {% if row.s2%}
-     <tr>
-        <td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td>
-        <td><a rev='[{{row.p2.curie}}]' href='{{row.s2.value}}'>{{row.p2.curie}}</a></td>
-    </tr>
-    {%endif %}
-    {% endfor %}
     </table>
-    </div>
+    </div>    
+    
+    <br/>
   </body>
 </html>
 VIEW`
 
-modelRdf=`cat <<QUERY
-DESCRIBE ?resource WHERE {
-  	[] a ?resource .
-}
-QUERY`
-
-viewRdf=`cat <<VIEW
-{{models.main|safe}}
-VIEW`
-
-modelTtl=$modelRdf
-viewTtl=$viewRdf
-modelNt=$modelRdf
-viewNt=$viewRdf
-modelJson=$modelRdf
-viewJson=$viewJson
 
 #Check models
-mainModelDir=$DIR/../../models/$initToken.$1
+mainDir=$DIR/../../components/$initToken/$1/
 
-if [ -e "$mainModelDir" ]
+if [ -e "$mainDir" ]
 then
   echo "WARNING: At least one model for $1 exists." >&2
 else
-  mkdir $mainModelDir
-fi
-
-obj=( )
-if [ "$2" == "all" ]
-then
-  obj=( html rdf ttl nt json )
-else
-  obj=( $2 )
-fi
-
-for i in ${obj[@]}
-do
-  if [ -e $mainModelDir/$i.queries ]
-  then
-    echo ERROR: $initToken.$1/$i.queries exists in models. Operation aborted >&2
-    exit 1
-  fi
-done
-
-
-#Check views
-mainViewDir=$DIR/../../views/$initToken.$1
-
-if [ -e "$mainViewDir" ]
-then
-  echo "WARNING: At least one view for $1 exists." >&2
-else
-  mkdir $mainViewDir
+  mkdir -p $mainDir/queries
 fi
 
+echo -e "$modelHtmlSP" > $mainDir/queries/sp.query
+echo -e "$modelHtmlPO" > $mainDir/queries/po.query
+echo -e "$viewHtml" > $mainDir/html.template
 
-for i in ${obj[@]}
-do
-  if [ -e $mainViewDir/$i.template ]
-  then
-    echo ERROR: $initToken.$1/$i already exist in views. Operation aborted >&2
-    exit 1
-  fi
-done
-
-
-#Create  file structure
-
-for i in ${obj[@]}
-do
-  mkdir $mainModelDir/$i.queries
-  if [ "$i" == "html" ]
-  then
-    echo "$modelHtml" > $mainModelDir/$i.queries/main.query
-    echo "$viewHtml" > $mainViewDir/$i.template
-  else
-    echo "$modelRdf" > $mainModelDir/$i.queries/main.query
-    echo "$viewRdf" > $mainViewDir/$i.template   
-  fi
-done
-
-echo $initToken.$1 created/modified successfully! >&2
+echo $1 created successfully! >&2
diff --git a/utils/modules/create-uri.sh b/utils/modules/create-uri.sh
index 9eb2dc39ba7a7045f44b2ae147e00fab677d1741..ae7380fb6334303ffd53a5ec2925d4270f9bde42 100755
--- a/utils/modules/create-uri.sh
+++ b/utils/modules/create-uri.sh
@@ -2,17 +2,29 @@
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
-initToken='uri'
+initToken='uris'
 
-modelHtml=`cat <<QUERY
-SELECT ?s2 ?p2 ?s1 ?p1  WHERE {
+modelHtmlSP=`cat <<QUERY
+SELECT ?s ?p  WHERE {
+  {
     GRAPH ?g{
-        {
-                <{{uri}}> ?s1 ?p1 .
-        }UNION{
-                ?s2 ?p2 <{{uri}}> .
-        }
+                ?s ?p <{{uri}}> .
     }
+  }UNION{     
+                ?s ?p <{{uri}}> .
+  }
+}
+QUERY`
+
+modelHtmlPO=`cat <<QUERY
+SELECT ?p ?o  WHERE {
+  {
+    GRAPH ?g{
+                <{{uri}}> ?p ?o.
+    }
+  }UNION{     
+                <{{uri}}> ?p ?o .
+  }
 }
 QUERY`
 
@@ -21,134 +33,73 @@ viewHtml=`cat <<VIEW
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
     "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" 
+    <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
     {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
-  <head>
+    <head>
     <title>Page about {{lodspk.this.value}}</title>
-    <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
-    <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version"   href="{{lodspk.this.value}}.rdf" />
-    <link rel="alternate" type="text/turtle"         title="Turtle Version"    href="{{lodspk.this.value}}.ttl" />
-    <link rel="alternate" type="text/plain"          title="N-Triples Version" href="{{lodspk.this.value}}.nt" />
-    <link rel="alternate" type="application/json"    title="RDFJSON Version"   href="{{lodspk.this.value}}.json" />
+    <link href="{{lodspk.home}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
+    <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{lodspk.this.value}}.rdf" />
+    <link rel="alternate" type="text/turtle" title="Turtle Version" href="{{lodspk.this.value}}.ttl" />
+    <link rel="alternate" type="text/plain" title="N-Triples Version" href="{{lodspk.this.value}}.nt" />
+    <link rel="alternate" type="application/json" title="RDFJSON Version" href="{{lodspk.this.value}}.json" />
   </head>
   <body about="{{lodspk.this.value}}">
-    <h1>Page about <a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></h1>
-  <div>
-    <h2>Information from {{lodspk.this.curie}}</h2>
+    <h1>Default view</h1>
+
+    <div style='margin-top: 40px'>
     <table>
-    {% for row in models.main %}
+    <tr><th>Subject</th><th>Predicate</th><th>Object</th></tr>
+    {% for row in models.po %}
+     <tr>
+<td>{%if forloop.first%}<a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a>{%endif%}</td>
+     <td style='background-color:#c9f9c9'><a href='{{row.p.value}}'>{{row.p.curie}}</a></td>
+     
+        <td style='background-color:#c9f9c9'>
+        {%if row.o.uri == 1%}
+        <a rev='[{{row.p.curie}}]' href='{{row.o.value}}'>{{row.o.curie}}</a>
+        {%else%}
+        {{row.o.value}}
+        {%endif%}
+        </td>
 
-      {% if row.s1%}
-      <tr>
-        <td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td>
+        </tr>
+    {% endfor %}
+<tr><td></td><td><a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></td><td></td></tr>
 
-        {% if row.p1.uri == 1 %}
-        <td><a rel='{{row.s1.curie}}' href='{{row.p1.value}}'>{{row.p1.curie}}</a></td>
-        {% else %}
-        <td><span property='{{row.s1.curie}}'>{{row.p1.value}}</span></td>
-        {% endif %}
+    {% for row in models.sp %}
+      <tr>
+        <td style='background-color:#c9f9c9'><a href='{{row.s.value}}'>{{row.s.curie}}</a></td>
 
+        <td style='background-color:#c9f9c9'><a rel='{{row.s.curie}}' href='{{row.p.value}}'>{{row.p.curie}}</a></td>
+<td>{%if forloop.first%}<a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a>{%endif%}</td>
         </tr>
-      {% endif %}
     {% endfor %}
-    </table>
+    <tr><th>Subject</th><th>Predicate</th><th>Object</th></tr>
 
-    <br/><br/>
-    <h2>Information pointing to {{lodspk.this.curie}}</h2>
-    <table>
-    {% for row in models.main %}
-      {% if row.s2%}
-     <tr>
-        <td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td>
-        <td><a rev='[{{row.p2.curie}}]' href='{{row.s2.value}}'>{{row.p2.curie}}</a></td>
-    </tr>
-    {%endif %}
-    {% endfor %}
     </table>
-    </div>
+    </div>    
+    
+    <br/>
   </body>
 </html>
 VIEW`
 
-modelRdf=`cat <<QUERY
-DESCRIBE ?resource WHERE {
-  	[] a ?resource .
-}
-QUERY`
-
-viewRdf=`cat <<VIEW
-{{r|safe}}
-VIEW`
-
-modelTtl=$modelRdf
-viewTtl=$viewRdf
-modelNt=$modelRdf
-viewNt=$viewRdf
-modelJson=$modelRdf
-viewJson=$viewJson
 
 #Check models
-mainModelDir=$DIR/../../models/$initToken.$1
+mainDir=$DIR/../../components/$initToken/$1
 
-if [ -e "$mainModelDir" ]
+if [ -e "$mainDir" ]
 then
   echo "WARNING: At least one model for $1 exists." >&2
 else
-  mkdir $mainModelDir
+  mkdir -p $mainDir
 fi
 
-obj=( )
-if [ "$2" == "all" ]
-then
-  obj=( html rdf ttl nt json )
-else
-  obj=( $2 )
-fi
-
-for i in ${obj[@]}
-do
-  if [ -e $mainModelDir/$i.queries ]
-  then
-    echo ERROR: $initToken.$1/$i.queries exists in models. Operation aborted >&2
-    exit 1
-  fi
-done
-
-
-#Check views
-mainViewDir=$DIR/../../views/$initToken.$1
-
-if [ -e "$mainViewDir" ]
-then
-  echo "WARNING: At least one view for $1 exists." >&2
-else
-  mkdir $mainViewDir
-fi
-
-
-for i in ${obj[@]}
-do
-  if [ -e $mainViewDir/$i.template ]
-  then
-    echo ERROR: $initToken.$1/$i already exist in views. Operation aborted >&2
-    exit 1
-  fi
-done
-
-
 #Create  file structure
 
-for i in ${obj[@]}
-do
-  mkdir $mainModelDir/$i.queries
-  if [ "$i" == "html" ]
-  then
-    echo "$modelHtml" > $mainModelDir/$i.queries/main.query
-    echo "$viewHtml" > $mainViewDir/$i.template
-  else
-    echo "$modelRdf" > $mainModelDir/$i.queries/main.query
-    echo "$viewRdf" > $mainViewDir/$i.template   
-  fi
-done
+mkdir $mainDir/queries
+echo -e "$modelHtmlSP" > $mainDir/queries/sp.query
+echo -e "$modelHtmlPO" > $mainDir/queries/po.query
+echo -e "$viewHtml" > $mainDir/html.template
 
 echo $initToken.$1 created/modified successfully! >&2
diff --git a/utils/modules/default.php b/utils/modules/default.php
new file mode 100644
index 0000000000000000000000000000000000000000..585721387ea5362f10f5ae54bc7685e2bb95dfe8
--- /dev/null
+++ b/utils/modules/default.php
@@ -0,0 +1,27 @@
+<?
+error_reporting(E_ERROR);
+$s = 'settings.inc.php';
+$c = file_get_contents($s);
+$optionarray = Array('on' => 'true', '1' => 'true', 'off' => 'false', '0' =>'false');
+$antiarray = Array('on' => 'false', '1' => 'false', 'off' => 'true', '0' =>'true');
+$option = $optionarray[$argv[1]];
+if($option == "" || $option == null){
+  echo "Option not recognized. Aborting\n";
+  exit(1);
+}
+if(preg_match('/disableComponents(.+)'.$optionarray[$argv[1]].'/', $c)){
+  echo "Default already turned ".$option."\n";
+  exit(0);
+}
+$newC = preg_replace('/disableComponents(.+)'.$antiarray[$argv[1]].'/', "disableComponents'] = ".$option, $c);
+if($newC == $c){
+  echo "WARNING: Variable 'disableComponents' does not exist. Adding it.\n";
+  $newC = preg_replace("/\?>/", "\n\$conf['disableComponents'] = ".$option.";\n?>", $c);
+}
+if(file_put_contents($s, $newC) === FALSE){
+  echo "An error ocurred";
+  exit(1);
+}else{
+  echo "Default mode turned ".$option."\n";
+}
+?>
diff --git a/utils/modules/delete-service.sh b/utils/modules/delete-service.sh
index 0adc58c37b811dd76647fffbf6ebd8442d625278..a496c7bbff58d53c29f4ee788fb6ce8c129fca8f 100755
--- a/utils/modules/delete-service.sh
+++ b/utils/modules/delete-service.sh
@@ -2,67 +2,18 @@
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
-initToken='service'
+initToken='services'
 
 
 #Check models
-mainModelDir=$DIR/../../models/$initToken.$1
-mainViewDir=$DIR/../../views/$initToken.$1
+mainDir=$DIR/../../components/$initToken/$1
 
-if [ ! -e "$mainModelDir" ]
+if [ ! -e "$mainDir" ]
 then
-  echo "ERROR: $initToken.$1 doesn't exist in models. Operation aborted" >&2
+  echo "ERROR: $initToken/	$1 doesn't exist in models. Operation aborted" >&2
   exit 1
 fi
 
-obj=( )
-if [ "$2" == "all" ]
-then
-  rm -rf $mainModelDir
-  rm -rf $mainViewDir
-  echo $initToken.$1 deleted >&2
-  exit
-else
-  obj=( $2 )
-fi
-
-for i in ${obj[@]}
-do
-  if [ ! -e $mainModelDir/$i.queries ]
-  then
-    echo "WARNING: $initToken.$1/$i.query does not exists in models." >&2
-  fi
-done
-
-
-#Check views
-
-if [ ! -e "$mainViewDir" ]
-then
-  echo "ERROR: $initToken.$1 doesn't exist in views. Operation aborted." >&2
-fi
-
-
-for i in ${obj[@]}
-do
-  if [ ! -e $mainViewDir/$i.template ]
-  then
-    echo "WARNING: $mainViewDir/$i.template doesn't exist in views." >&2
-  fi
-done
-
+rm -rf $mainDir
 
-#Delete  file structure
-
-if [ "$2" == "all" ]
-then
-  rm -rf $mainModelDir
-  rm -rf $mainViewDir
-else
-  for i in ${obj[@]}
-  do
-    rm -rf  $mainModelDir/$i.queries
-    rm -rf  $mainViewDir/$i.template   
-  done
-fi
-echo $initToken.$1 deleted >&2
+echo Service $1 deleted >&2
diff --git a/utils/modules/delete-type.sh b/utils/modules/delete-type.sh
index c934f7e7e41c6c403d48b3a819046409005e09e5..9cddaf897898a3b5d7eb095244fc5ee679da786f 100755
--- a/utils/modules/delete-type.sh
+++ b/utils/modules/delete-type.sh
@@ -2,67 +2,19 @@
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
-initToken='type'
+initToken='types'
 
 
 #Check models
-mainModelDir=$DIR/../../models/$initToken.$1
-mainViewDir=$DIR/../../views/$initToken.$1
+mainDir=$DIR/../../components/$initToken/$1
 
-if [ ! -e "$mainModelDir" ]
+if [ ! -e "$mainDir" ]
 then
-  echo "ERROR: $initToken.$1 doesn't exist in models. Operation aborted" >&2
+  echo "ERROR: $initToken/$1 doesn't exist in models. Operation aborted" >&2
   exit 1
 fi
 
-obj=( )
-if [ "$2" == "all" ]
-then
-  rm -rf $mainModelDir
-  rm -rf $mainViewDir
-  echo $initToken.$1 deleted >&2
-  exit
-else
-  obj=( $2 )
-fi
-
-for i in ${obj[@]}
-do
-  if [ ! -e $mainModelDir/$i.queries ]
-  then
-    echo "WARNING: $initToken.$1/$i.query does not exists in models." >&2
-  fi
-done
-
-
-#Check views
-
-if [ ! -e "$mainViewDir" ]
-then
-  echo "ERROR: $initToken.$1 doesn't exist in views. Operation aborted." >&2
-fi
-
-
-for i in ${obj[@]}
-do
-  if [ ! -e $mainViewDir/$i.template ]
-  then
-    echo "WARNING: $mainViewDir/$i.template doesn't exist in views." >&2
-  fi
-done
-
-
 #Delete  file structure
 
-if [ "$2" == "all" ]
-then
-  rm -rf $mainModelDir
-  rm -rf $mainViewDir
-else
-  for i in ${obj[@]}
-  do
-    rm -rf  $mainModelDir/$i.queries
-    rm -rf  $mainViewDir/$i.template   
-  done
-fi
+rm -rf $mainDir
 echo $initToken.$1 deleted successfully! >&2
diff --git a/utils/modules/delete-uri.sh b/utils/modules/delete-uri.sh
index a247cb67e549a446bac6675a0bf68a298f0d5bf4..e868c51f3e3e580959f2d2855a7af5cbe5513436 100755
--- a/utils/modules/delete-uri.sh
+++ b/utils/modules/delete-uri.sh
@@ -2,67 +2,18 @@
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
-initToken='uri'
+initToken='uris'
 
 
 #Check models
-mainModelDir=$DIR/../../models/$initToken.$1
-mainViewDir=$DIR/../../views/$initToken.$1
+mainDir=$DIR/../../components/$initToken/$1
 
-if [ ! -e "$mainModelDir" ]
+if [ ! -e "$mainDir" ]
 then
-  echo "ERROR: $initToken.$1 doesn't exist in models. Operation aborted" >&2
+  echo "ERROR: $mainDir doesn't exist in models. Operation aborted" >&2
   exit 1
 fi
 
-obj=( )
-if [ "$2" == "all" ]
-then
-  rm -rf $mainModelDir
-  rm -rf $mainViewDir
-  echo $initToken.$1 deleted >&2
-  exit
-else
-  obj=( $2 )
-fi
-
-for i in ${obj[@]}
-do
-  if [ ! -e $mainModelDir/$i.queries ]
-  then
-    echo "WARNING: $initToken.$1/$i.query does not exists in models." >&2
-  fi
-done
-
-
-#Check views
-
-if [ ! -e "$mainViewDir" ]
-then
-  echo "ERROR: $initToken.$1 doesn't exist in views. Operation aborted." >&2
-fi
-
-
-for i in ${obj[@]}
-do
-  if [ ! -e $mainViewDir/$i.template ]
-  then
-    echo "WARNING: $mainViewDir/$i.template doesn't exist in views." >&2
-  fi
-done
-
+rm -rf $mainDir
 
-#Delete  file structure
-
-if [ "$2" == "all" ]
-then
-  rm -rf $mainModelDir
-  rm -rf $mainViewDir
-else
-  for i in ${obj[@]}
-  do
-    rm -rf  $mainModelDir/$i.queries
-    rm -rf  $mainViewDir/$i.template   
-  done
-fi
-echo $initToken.$1 deleted successfully! >&2
+echo Uri $1 deleted >&2
diff --git a/utils/modules/restore.sh b/utils/modules/restore.sh
index cc330da8fd1f75f6ba2dc30ff58c5a3fdecd345a..dd18187a8a2309bd5cb131667d66b05dcd847536 100755
--- a/utils/modules/restore.sh
+++ b/utils/modules/restore.sh
@@ -12,8 +12,12 @@ if [[ ! -d $BACKUPDIR ]]; then
   exit 1
 fi
 
-LIST=( `ls $BACKUPDIR/$NAME-backup*` )
+LIST=( `ls $BACKUPDIR/$NAME-backup* 2>/dev/null` )
 CHOSEN=-1
+if [ "${#LIST[@]}" -eq 0 ];then
+  echo "No backups available";
+  exit
+fi
 while [[ "$CHOSEN" -lt 0 || "$CHOSEN" -ge "${#LIST[@]}" ]] ;do
 j=0
 echo
diff --git a/utils/modules/version.sh b/utils/modules/version.sh
new file mode 100755
index 0000000000000000000000000000000000000000..7f36515bfe525d7f0e226af7faea03cf33a6695c
--- /dev/null
+++ b/utils/modules/version.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+FILE=README
+cd $DIR/../..
+grep -E "^version" $FILE |head -1 |sed -e 's/version: //'
diff --git a/views/type.rdfs:Resource/html.template b/views/type.rdfs:Resource/html.template
deleted file mode 100644
index 6b5a78bde0888e15c32443f3933f6808e61c4e76..0000000000000000000000000000000000000000
--- a/views/type.rdfs:Resource/html.template
+++ /dev/null
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
-    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
-    <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" 
-    {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
-    <head>
-    <title>Page about {{lodspk.this.value}}</title>
-    <link href="{{lodspk.home}}css/basic.css" rel="stylesheet" type="text/css" media="screen" />
-    <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{lodspk.this.value}}.rdf" />
-    <link rel="alternate" type="text/turtle" title="Turtle Version" href="{{lodspk.this.value}}.ttl" />
-    <link rel="alternate" type="text/plain" title="N-Triples Version" href="{{lodspk.this.value}}.nt" />
-    <link rel="alternate" type="application/json" title="RDFJSON Version" href="{{lodspk.this.value}}.json" />
-  </head>
-  <body about="{{lodspk.this.value}}">
-    <h1>Page about <a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></h1>
-  {{lodspk.endpoint.local}}
-    <div>
-    <h2>Information from {{lodspk.this.curie}}</h2>
-    <table>
-    {% for row in models.main %}
-
-      {% if row.s1%}
-      <tr>
-        <td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td>
-
-        {% if row.p1.uri == 1 %}
-        <td><a rel='{{row.s1.curie}}' href='{{row.p1.value}}'>{{row.p1.curie}}</a></td>
-        {% else %}
-        <td><span property='{{row.s1.curie}}'>{{row.p1.value}}</span></td>
-        {% endif %}
-
-        </tr>
-      {% endif %}
-    {% endfor %}
-    </table>
-
-    <br/><br/>
-    <h2>Information pointing to {{lodspk.this.curie}}</h2>
-    <table>
-    {% for row in models.main %}
-      {% if row.s2%}
-     <tr>
-        <td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td>
-        <td><a rev='[{{row.p2.curie}}]' href='{{row.s2.value}}'>{{row.p2.curie}}</a></td>
-    </tr>
-    {%endif %}
-    {% endfor %}
-    </table>
-    </div>
-  </body>
-</html>