diff --git a/docs/simplesamlphp-modules.md b/docs/simplesamlphp-modules.md
index ccbb851c81223793ed5dc742b2e26efe3014c460..92482287a9ead9aded9efecd6c3f7c88ecf5b7f6 100644
--- a/docs/simplesamlphp-modules.md
+++ b/docs/simplesamlphp-modules.md
@@ -66,7 +66,7 @@ dictionaries
 
 :   It is also possible to specify
     `<module name>:<dictionary name>` as the default
-    dictionary when instantiating the `SimpleSAML_XHTML_Template`
+    dictionary when instantiating the `\SimpleSAML\XHTML\Template`
     class.
 
 hooks
@@ -90,7 +90,7 @@ templates
 :   These are module-specific templates. To use one of these
     templates, specify `<module name>:<template file>.php`
     as the template file in the constructor of
-    `SimpleSAML_XHTML_Template`. For example, `example:login-form.php`
+    `\SimpleSAML\XHTML\Template`. For example, `example:login-form.php`
     is translated to the file
     `modules/example/templates/default/login-form.php`. Note that
     `default` in the previous example is defined by the `theme.use`
diff --git a/lib/SimpleSAML/Error/Error.php b/lib/SimpleSAML/Error/Error.php
index aceac89f95a8e2d033f807aa0199c266d817e629..f02b4be1cc98af037d589bce8a3ddc7065f9e3a7 100644
--- a/lib/SimpleSAML/Error/Error.php
+++ b/lib/SimpleSAML/Error/Error.php
@@ -284,7 +284,7 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception
             call_user_func($show_function, $config, $data);
             assert(false);
         } else {
-            $t = new SimpleSAML_XHTML_Template($config, 'error.php', 'errors');
+            $t = new \SimpleSAML\XHTML\Template($config, 'error.php', 'errors');
             $t->data = array_merge($t->data, $data);
             $t->data['dictTitleTranslated'] = $t->getTranslator()->t($t->data['dictTitle']);
             $t->data['dictDescrTranslated'] = $t->getTranslator()->t($t->data['dictDescr'], $t->data['parameters']);
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index a6641ac6be3629e08322dcd748d0e24119b3e663..c1bb1bbdf77a01ec1a875253d85c1fec98b1e4ef 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -13,7 +13,6 @@ use SimpleSAML\Session;
  */
 class HTTP
 {
-
     /**
      * Obtain a URL where we can redirect to securely post a form with the given data to a specific destination.
      *
@@ -1215,7 +1214,7 @@ class HTTP
             self::redirect(self::getSecurePOSTRedirectURL($destination, $data));
         }
 
-        $p = new \SimpleSAML_XHTML_Template($config, 'post.php');
+        $p = new \SimpleSAML\XHTML\Template($config, 'post.php');
         $p->data['destination'] = $destination;
         $p->data['post'] = $data;
         $p->show();
diff --git a/lib/SimpleSAML/XHTML/EMail.php b/lib/SimpleSAML/XHTML/EMail.php
index 5796ec1c028f7cf6b745465a8259dd984e4a65f8..c09b17e2fc96588d1e9c88fca5aac7f39657f245 100644
--- a/lib/SimpleSAML/XHTML/EMail.php
+++ b/lib/SimpleSAML/XHTML/EMail.php
@@ -1,12 +1,15 @@
 <?php
 
+namespace SimpleSAML\XHTML;
+
 /**
  * A minimalistic Emailer class. Creates and sends HTML emails.
  *
  * @author Andreas kre Solberg, UNINETT AS. <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class SimpleSAML_XHTML_EMail
+
+class EMail
 {
     private $to = null;
     private $cc = null;
@@ -78,11 +81,11 @@ pre {
     public function send()
     {
         if ($this->to === null) {
-            throw new Exception('EMail field [to] is required and not set.');
+            throw new \Exception('EMail field [to] is required and not set.');
         } elseif ($this->subject === null) {
-            throw new Exception('EMail field [subject] is required and not set.');
+            throw new \Exception('EMail field [subject] is required and not set.');
         } elseif ($this->body === null) {
-            throw new Exception('EMail field [body] is required and not set.');
+            throw new \Exception('EMail field [body] is required and not set.');
         }
 
         $random_hash = bin2hex(openssl_random_pseudo_bytes(16));
@@ -114,9 +117,9 @@ Content-Transfer-Encoding: 8bit
         $headers = implode("\n", $this->headers);
 
         $mail_sent = @mail($this->to, $this->subject, $message, $headers);
-        SimpleSAML\Logger::debug('Email: Sending e-mail to [' . $this->to . '] : ' . ($mail_sent ? 'OK' : 'Failed'));
+        \SimpleSAML\Logger::debug('Email: Sending e-mail to [' . $this->to . '] : ' . ($mail_sent ? 'OK' : 'Failed'));
         if (!$mail_sent) {
-            throw new Exception('Error when sending e-mail');
+            throw new \Exception('Error when sending e-mail');
         }
     }
 }
diff --git a/lib/SimpleSAML/XHTML/IdPDisco.php b/lib/SimpleSAML/XHTML/IdPDisco.php
index 57a95b99b1317adbca35303050059ef8063057f1..e362ff711f5db7a67be158700c1393d2e3ca51bd 100644
--- a/lib/SimpleSAML/XHTML/IdPDisco.php
+++ b/lib/SimpleSAML/XHTML/IdPDisco.php
@@ -1,5 +1,6 @@
 <?php
 
+namespace SimpleSAML\XHTML;
 
 /**
  * This class implements a generic IdP discovery service, for use in various IdP
@@ -13,9 +14,9 @@
  * @author Andreas Ă…kre Solberg <andreas@uninett.no>, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class SimpleSAML_XHTML_IdPDisco
-{
 
+class IdPDisco
+{
     /**
      * An instance of the configuration class.
      *
@@ -585,7 +586,7 @@ class SimpleSAML_XHTML_IdPDisco
                 throw new Exception('Invalid value for the \'idpdisco.layout\' option.');
         }
 
-        $t = new SimpleSAML_XHTML_Template($this->config, $templateFile, 'disco');
+        $t = new Template($this->config, $templateFile, 'disco');
         $t->data['idplist'] = $idpList;
         $t->data['preferredidp'] = $preferredIdP;
         $t->data['return'] = $this->returnURL;
diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index beadfa6ca294c53c4978df002394d9cbe27ce55b..5d29eaf2d326d9ff2d7f1ea3c450c73d68e9d080 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -1,5 +1,6 @@
 <?php
 
+namespace SimpleSAML\XHTML;
 
 /**
  * A minimalistic XHTML PHP based template system implemented for SimpleSAMLphp.
@@ -11,7 +12,7 @@
 use JaimePerez\TwigConfigurableI18n\Twig\Environment as Twig_Environment;
 use JaimePerez\TwigConfigurableI18n\Twig\Extensions\Extension\I18n as Twig_Extensions_Extension_I18n;
 
-class SimpleSAML_XHTML_Template
+class Template
 {
     /**
      * The data associated with this template, accessible within the template itself.
@@ -72,9 +73,9 @@ class SimpleSAML_XHTML_Template
      *
      * Used to intercept certain parts of the template handling, while keeping away unwanted/unexpected hooks. Set
      * the 'theme.controller' configuration option to a class that implements the
-     * SimpleSAML\XHTML\TemplateControllerInterface interface to use it.
+     * \SimpleSAML\XHTML\TemplateControllerInterface interface to use it.
      *
-     * @var SimpleSAML\XHTML\TemplateControllerInterface
+     * @var \SimpleSAML\XHTML\TemplateControllerInterface
      */
     private $controller;
 
@@ -113,7 +114,7 @@ class SimpleSAML_XHTML_Template
         );
 
         // initialize internationalization system
-        $this->translator = new SimpleSAML\Locale\Translate($configuration, $defaultDictionary);
+        $this->translator = new \SimpleSAML\Locale\Translate($configuration, $defaultDictionary);
         $this->localization = new \SimpleSAML\Locale\Localization($configuration);
 
         // check if we need to attach a theme controller
@@ -154,8 +155,8 @@ class SimpleSAML_XHTML_Template
     /**
      * Set up the places where twig can look for templates.
      *
-     * @return Twig_Loader_Filesystem The twig template loader or false if the template does not exist.
-     * @throws Twig_Error_Loader In case a failure occurs.
+     * @return \Twig_Loader_Filesystem The twig template loader or false if the template does not exist.
+     * @throws \Twig_Error_Loader In case a failure occurs.
      */
     private function setupTwigTemplatepaths()
     {
@@ -226,8 +227,8 @@ class SimpleSAML_XHTML_Template
             );
         } // TODO: add a branch for the old SimpleSAMLphp backend
 
-        $twig = new Twig_Environment($loader, $options);
-        $twig->addExtension(new Twig_Extensions_Extension_I18n());
+        $twig = new \Twig_Environment($loader, $options);
+        $twig->addExtension(new \Twig_Extensions_Extension_I18n());
 
         // initialize some basic context
         $langParam = $this->configuration->getString('language.parameter.name', 'language');
@@ -301,18 +302,18 @@ class SimpleSAML_XHTML_Template
      *
      * @return string The templates directory of a module.
      *
-     * @throws InvalidArgumentException If the module is not enabled or it has no templates directory.
+     * @throws \InvalidArgumentException If the module is not enabled or it has no templates directory.
      */
     private function getModuleTemplateDir($module)
     {
         if (!\SimpleSAML\Module::isModuleEnabled($module)) {
-            throw new InvalidArgumentException('The module \''.$module.'\' is not enabled.');
+            throw new \InvalidArgumentException('The module \''.$module.'\' is not enabled.');
         }
         $moduledir = \SimpleSAML\Module::getModuleDir($module);
         // check if module has a /templates dir, if so, append
         $templatedir = $moduledir.'/templates';
         if (!is_dir($templatedir)) {
-            throw new InvalidArgumentException('The module \''.$module.'\' has no templates directory.');
+            throw new \InvalidArgumentException('The module \''.$module.'\' has no templates directory.');
         }
         return $templatedir;
     }
@@ -325,12 +326,12 @@ class SimpleSAML_XHTML_Template
      *
      * @param string $module The module where we need to search for templates.
      *
-     * @throws InvalidArgumentException If the module is not enabled or it has no templates directory.
+     * @throws \InvalidArgumentException If the module is not enabled or it has no templates directory.
      */
     public function addTemplatesFromModule($module)
     {
         $dir = $this->getModuleTemplateDir($module);
-        /** @var Twig_Loader_Filesystem $loader */
+        /** @var \Twig_Loader_Filesystem $loader */
         $loader = $this->twig->getLoader();
         $loader->addPath($dir, $module);
     }
@@ -444,7 +445,7 @@ class SimpleSAML_XHTML_Template
      *
      * @return string The absolute path to the template file.
      *
-     * @throws Exception If the template file couldn't be found.
+     * @throws \Exception If the template file couldn't be found.
      */
     private function findTemplatePath($template, $throw_exception = true)
     {
@@ -496,7 +497,7 @@ class SimpleSAML_XHTML_Template
             $error = 'Template: Could not find template file ['.$template.'] at ['.$filename.']';
             \SimpleSAML\Logger::critical($_SERVER['PHP_SELF'].' - '.$error);
 
-            throw new Exception($error);
+            throw new \Exception($error);
         } else {
             // missing template expected, return NULL
             return null;
@@ -518,7 +519,7 @@ class SimpleSAML_XHTML_Template
     /**
      * Get the current instance of Twig in use.
      *
-     * @return false|Twig_Environment The Twig instance in use, or false if Twig is not used.
+     * @return false|\Twig_Environment The Twig instance in use, or false if Twig is not used.
      */
     public function getTwig()
     {
diff --git a/modules/adfs/www/idp/metadata.php b/modules/adfs/www/idp/metadata.php
index 20a745aee47eb8b76c6e0ea6edee5970bb31ab18..22f0a7b38e47217231a0ca943cd4dd8a3e1e47c8 100644
--- a/modules/adfs/www/idp/metadata.php
+++ b/modules/adfs/www/idp/metadata.php
@@ -144,7 +144,7 @@ try {
     if ($output_xhtml) {
         $defaultidp = $config->getString('default-adfs-idp', null);
 
-        $t = new SimpleSAML_XHTML_Template($config, 'metadata.php', 'admin');
+        $t = new \SimpleSAML\XHTML\Template($config, 'metadata.php', 'admin');
 
         $t->data['clipboard.js'] = true;
         $t->data['available_certs'] = $availableCerts;
diff --git a/modules/authX509/lib/Auth/Source/X509userCert.php b/modules/authX509/lib/Auth/Source/X509userCert.php
index a03b96c1d2d5fdbb2dd1e47e9cd112d4d4b4d72c..49860c2c6ae62ae4220775750b74a414b0bbb235 100644
--- a/modules/authX509/lib/Auth/Source/X509userCert.php
+++ b/modules/authX509/lib/Auth/Source/X509userCert.php
@@ -6,9 +6,9 @@
  * @author Emmanuel Dreyfus <manu@netbsd.org>
  * @package SimpleSAMLphp
  */
+
 class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
 {
-
     /**
      * x509 attributes to use from the certificate for searching the user in the LDAP directory.
      */
@@ -70,9 +70,9 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
     {
         $config = \SimpleSAML\Configuration::getInstance();
 
-        $t = new SimpleSAML_XHTML_Template($config, 'authX509:X509error.php');
+        $t = new \SimpleSAML\XHTML\Template($config, 'authX509:X509error.php');
         $t->data['errorcode'] = $state['authX509.error'];
-        $t->data['errorcodes'] = SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
+        $t->data['errorcodes'] = \SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
 
         $t->show();
         exit();
diff --git a/modules/authX509/www/expirywarning.php b/modules/authX509/www/expirywarning.php
index 7b1671317f320ae81611b15ef6ea223da1ef7658..73b3f86581132bd26e94afc0fefd5873a31a2fda 100644
--- a/modules/authX509/www/expirywarning.php
+++ b/modules/authX509/www/expirywarning.php
@@ -6,26 +6,26 @@
  * @package SimpleSAMLphp
  */
 
-SimpleSAML\Logger::info('AuthX509 - Showing expiry warning to user');
+\SimpleSAML\Logger::info('AuthX509 - Showing expiry warning to user');
 
 if (!array_key_exists('StateId', $_REQUEST)) {
-    throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
+    throw new \SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = SimpleSAML_Auth_State::loadState($id, 'warning:expire');
+$state = \SimpleSAML_Auth_State::loadState($id, 'warning:expire');
 
 
 if (array_key_exists('proceed', $_REQUEST)) {
     // The user has pressed the proceed-button
-    SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+    \SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'authX509:X509warning.php');
-$t->data['target'] = SimpleSAML\Module::getModuleURL('authX509/expirywarning.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'authX509:X509warning.php');
+$t->data['target'] = \SimpleSAML\Module::getModuleURL('authX509/expirywarning.php');
 $t->data['data'] = array('StateId' => $id);
 $t->data['daysleft'] = $state['daysleft'];
 $t->data['renewurl'] = $state['renewurl'];
-$t->data['errorcodes'] = SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
+$t->data['errorcodes'] = \SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
 $t->show();
diff --git a/modules/authYubiKey/www/yubikeylogin.php b/modules/authYubiKey/www/yubikeylogin.php
index 5fa9ee701ad4c0d2e67965a2ee5658560f98ee0a..7b6c94f2f0073bb2e7aa0650196f79118d2f3c46 100644
--- a/modules/authYubiKey/www/yubikeylogin.php
+++ b/modules/authYubiKey/www/yubikeylogin.php
@@ -10,7 +10,7 @@
  */
 
 if (!array_key_exists('AuthState', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing AuthState parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing AuthState parameter.');
 }
 $authStateId = $_REQUEST['AuthState'];
 
@@ -22,17 +22,17 @@ if (array_key_exists('otp', $_REQUEST)) {
 
 if (!empty($otp)) {
 	// attempt to log in
-	$errorCode = sspmod_authYubiKey_Auth_Source_YubiKey::handleLogin($authStateId, $otp);
+	$errorCode = \sspmod_authYubiKey_Auth_Source_YubiKey::handleLogin($authStateId, $otp);
 } else {
 	$errorCode = NULL;
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'authYubiKey:yubikeylogin.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'authYubiKey:yubikeylogin.php');
 $t->data['stateparams'] = array('AuthState' => $authStateId);
 $t->data['errorcode'] = $errorCode;
-$t->data['errorcodes'] = SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
-$t->data['logo_url'] = SimpleSAML\Module::getModuleURL('authYubiKey/resources/logo.jpg');
-$t->data['devicepic_url'] = SimpleSAML\Module::getModuleURL('authYubiKey/resources/yubikey.jpg');
+$t->data['errorcodes'] = \SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
+$t->data['logo_url'] = \SimpleSAML\Module::getModuleURL('authYubiKey/resources/logo.jpg');
+$t->data['devicepic_url'] = \SimpleSAML\Module::getModuleURL('authYubiKey/resources/yubikey.jpg');
 $t->show();
 exit();
diff --git a/modules/authorize/www/authorize_403.php b/modules/authorize/www/authorize_403.php
index fec588740d4e8c70356bb1de23533beec4708f1b..a9ebc83624ea5290d3a41c44696b9e13a88bcbb1 100644
--- a/modules/authorize/www/authorize_403.php
+++ b/modules/authorize/www/authorize_403.php
@@ -6,14 +6,14 @@
  */
 
 if (!array_key_exists('StateId', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['StateId'], 'authorize:Authorize');
+$state = \SimpleSAML_Auth_State::loadState($_REQUEST['StateId'], 'authorize:Authorize');
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'authorize:authorize_403.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'authorize:authorize_403.php');
 if (isset($state['Source']['auth'])) {
-    $t->data['LogoutURL'] = SimpleSAML\Module::getModuleURL('core/authenticate.php', array('as' => $state['Source']['auth']))."&logout";
+    $t->data['LogoutURL'] = \SimpleSAML\Module::getModuleURL('core/authenticate.php', array('as' => $state['Source']['auth']))."&logout";
 }
 header('HTTP/1.0 403 Forbidden');
 $t->show();
diff --git a/modules/consent/templates/consentform.php b/modules/consent/templates/consentform.php
index d9be45d3249e7b3947caed38815ed8080edd00f2..338434d195df5928c13569ea8ac5f80e63d950f9 100644
--- a/modules/consent/templates/consentform.php
+++ b/modules/consent/templates/consentform.php
@@ -131,9 +131,9 @@ if ($this->data['sppp'] !== false) {
 /**
  * Recursive attribute array listing function
  *
- * @param SimpleSAML_XHTML_Template $t          Template object
- * @param array                     $attributes Attributes to be presented
- * @param string                    $nameParent Name of parent element
+ * @param \SimpleSAML\XHTML\Template $t          Template object
+ * @param array                      $attributes Attributes to be presented
+ * @param string                     $nameParent Name of parent element
  *
  * @return string HTML representation of the attributes 
  */
diff --git a/modules/consent/www/getconsent.php b/modules/consent/www/getconsent.php
index 1e936d4351ed26a23332588e330698852b8263a1..652df202a3bd13323b2ff4ed19b97bb507ecc37a 100644
--- a/modules/consent/www/getconsent.php
+++ b/modules/consent/www/getconsent.php
@@ -55,7 +55,7 @@ if (array_key_exists('yes', $_REQUEST)) {
     if (isset($state['Destination']['entityid'])) {
         $statsInfo['spEntityID'] = $state['Destination']['entityid'];
     }
-    SimpleSAML_Stats::log('consent:accept', $statsInfo);
+    \SimpleSAML_Stats::log('consent:accept', $statsInfo);
 
     if (   array_key_exists('consent:store', $state) 
         && array_key_exists('saveconsent', $_REQUEST)
@@ -67,7 +67,7 @@ if (array_key_exists('yes', $_REQUEST)) {
         $targetedId = $state['consent:store.destination'];
         $attributeSet = $state['consent:store.attributeSet'];
 
-        SimpleSAML\Logger::debug(
+        \SimpleSAML\Logger::debug(
             'Consent - saveConsent() : [' . $userId . '|' .
             $targetedId . '|' .  $attributeSet . ']'
         );	
@@ -78,7 +78,7 @@ if (array_key_exists('yes', $_REQUEST)) {
         }
     }
 
-    SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+    \SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
 }
 
 // Prepare attributes for presentation
@@ -99,12 +99,12 @@ $para = array(
 SimpleSAML\Module::callHooks('attributepresentation', $para);
 
 // Make, populate and layout consent form
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'consent:consentform.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'consent:consentform.php');
 $t->data['srcMetadata'] = $state['Source'];
 $t->data['dstMetadata'] = $state['Destination'];
-$t->data['yesTarget'] = SimpleSAML\Module::getModuleURL('consent/getconsent.php');
+$t->data['yesTarget'] = \SimpleSAML\Module::getModuleURL('consent/getconsent.php');
 $t->data['yesData'] = array('StateId' => $id);
-$t->data['noTarget'] = SimpleSAML\Module::getModuleURL('consent/noconsent.php');
+$t->data['noTarget'] = \SimpleSAML\Module::getModuleURL('consent/noconsent.php');
 $t->data['noData'] = array('StateId' => $id);
 $t->data['attributes'] = $attributes;
 $t->data['checked'] = $state['consent:checked'];
diff --git a/modules/consent/www/logout.php b/modules/consent/www/logout.php
index 2d46540df73b23eb61cf54aeed83ac02c590e27a..84eca697cb2b194be83cf313876c044a79ceb860 100644
--- a/modules/consent/www/logout.php
+++ b/modules/consent/www/logout.php
@@ -6,12 +6,12 @@
  */
 
 if (!array_key_exists('StateId', $_GET)) {
-    throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
+    throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
-$state = SimpleSAML_Auth_State::loadState($_GET['StateId'], 'consent:request');
+$state = \SimpleSAML_Auth_State::loadState($_GET['StateId'], 'consent:request');
 
 $state['Responder'] = array('sspmod_consent_Logout', 'postLogout');
 
-$idp = SimpleSAML_IdP::getByState($state);
+$idp = \SimpleSAML_IdP::getByState($state);
 $idp->handleLogoutRequest($state, null);
 assert(false);
diff --git a/modules/consent/www/logout_completed.php b/modules/consent/www/logout_completed.php
index e0d2a077a2028b6774c24c487da9f2f28ee5fb23..a5124704f3a192dc6c9fd106ced8d69fc3961785 100644
--- a/modules/consent/www/logout_completed.php
+++ b/modules/consent/www/logout_completed.php
@@ -6,5 +6,5 @@
  */
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'consent:logout_completed.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'consent:logout_completed.php');
 $t->show();
diff --git a/modules/consent/www/noconsent.php b/modules/consent/www/noconsent.php
index 9a73b0b71c33bb1f4d6b659f52b9500417fc54d8..f6ae875285c285721acc65b5bb74b01f9ae1e3d6 100644
--- a/modules/consent/www/noconsent.php
+++ b/modules/consent/www/noconsent.php
@@ -1,24 +1,26 @@
 <?php
+
 /**
  * This is the page the user lands on when choosing "no" in the consent form.
  *
  * @package SimpleSAMLphp
  */
+
 if (!array_key_exists('StateId', $_REQUEST)) {
-    throw new SimpleSAML_Error_BadRequest(
+    throw new \SimpleSAML_Error_BadRequest(
         'Missing required StateId query parameter.'
     );
 }
 
 $id = $_REQUEST['StateId'];
-$state = SimpleSAML_Auth_State::loadState($id, 'consent:request');
+$state = \SimpleSAML_Auth_State::loadState($id, 'consent:request');
 
-$resumeFrom = SimpleSAML\Module::getModuleURL(
+$resumeFrom = \SimpleSAML\Module::getModuleURL(
     'consent/getconsent.php',
     array('StateId' => $id)
 );
 
-$logoutLink = SimpleSAML\Module::getModuleURL(
+$logoutLink = \SimpleSAML\Module::getModuleURL(
     'consent/logout.php',
     array('StateId' => $id)
 );
@@ -35,11 +37,11 @@ $statsInfo = array();
 if (isset($state['Destination']['entityid'])) {
     $statsInfo['spEntityID'] = $state['Destination']['entityid'];
 }
-SimpleSAML_Stats::log('consent:reject', $statsInfo);
+\SimpleSAML_Stats::log('consent:reject', $statsInfo);
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'consent:noconsent.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'consent:noconsent.php');
 $t->data['dstMetadata'] = $state['Destination'];
 $t->data['resumeFrom'] = $resumeFrom;
 $t->data['aboutService'] = $aboutService;
diff --git a/modules/consentAdmin/www/consentAdmin.php b/modules/consentAdmin/www/consentAdmin.php
index eee9cf44b4ba64862154f194e7e8dfd305c48228..5e8dc0cc1a828e02676a84d9cb7003e19a59ce15 100644
--- a/modules/consentAdmin/www/consentAdmin.php
+++ b/modules/consentAdmin/www/consentAdmin.php
@@ -192,12 +192,12 @@ if ($action !== null && $sp_entityid !== null) {
             }
             // Unknown action (should not happen)
         } else {
-            SimpleSAML\Logger::info('consentAdmin: unknown action');
+            \SimpleSAML\Logger::info('consentAdmin: unknown action');
             $res = "unknown";
         }
     }
     // init template to enable translation of status messages
-    $template = new SimpleSAML_XHTML_Template($config, 'consentAdmin:consentadminajax.php', 'consentAdmin:consentadmin');
+    $template = new \SimpleSAML\XHTML\Template($config, 'consentAdmin:consentadminajax.php', 'consentAdmin:consentadmin');
     $template->data['res'] = $res;
     $template->show();
     exit;
@@ -215,7 +215,7 @@ foreach ($user_consent_list as $c) {
 $template_sp_content = array();
 
 // Init template
-$template = new SimpleSAML_XHTML_Template($config, 'consentAdmin:consentadmin.php', 'consentAdmin:consentadmin');
+$template = new \SimpleSAML\XHTML\Template($config, 'consentAdmin:consentadmin.php', 'consentAdmin:consentadmin');
 $translator = $template->getTranslator();
 $translator->includeLanguageFile('attributes.php'); // attribute listings translated by this dictionary
 $sp_empty_name = $translator->getTag('sp_empty_name');
diff --git a/modules/core/www/as_login.php b/modules/core/www/as_login.php
index e43a77898b7d7faa6d17279003fddad88aee2279..d8dd4382cbb043d37a07fe76a2fa3b8a631df990 100644
--- a/modules/core/www/as_login.php
+++ b/modules/core/www/as_login.php
@@ -7,11 +7,11 @@
  */
 
 if (!isset($_REQUEST['ReturnTo'])) {
-	throw new SimpleSAML_Error_BadRequest('Missing ReturnTo parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing ReturnTo parameter.');
 }
 
 if (!isset($_REQUEST['AuthId'])) {
-	throw new SimpleSAML_Error_BadRequest('Missing AuthId parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing AuthId parameter.');
 }
 
 /*
diff --git a/modules/core/www/as_logout.php b/modules/core/www/as_logout.php
index bfd92341534a75c243bc33a76944c2f9b564d9e3..bac8b042d43f66260f9ec0b4de66097af38a3d9b 100644
--- a/modules/core/www/as_logout.php
+++ b/modules/core/www/as_logout.php
@@ -7,11 +7,11 @@
  */
 
 if (!isset($_REQUEST['ReturnTo']) || !is_string($_REQUEST['ReturnTo'])) {
-	throw new SimpleSAML_Error_BadRequest('Missing ReturnTo parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing ReturnTo parameter.');
 }
 
 if (!isset($_REQUEST['AuthId']) || !is_string($_REQUEST['AuthId'])) {
-	throw new SimpleSAML_Error_BadRequest('Missing AuthId parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing AuthId parameter.');
 }
 
 $as = new \SimpleSAML\Auth\Simple($_REQUEST['AuthId']);
diff --git a/modules/core/www/authenticate.php b/modules/core/www/authenticate.php
index ed56c6a0649d7a09ee1f6564941083fa98740af7..47a922044c200d25426a8d1f9b03e8ed185850bb 100644
--- a/modules/core/www/authenticate.php
+++ b/modules/core/www/authenticate.php
@@ -3,9 +3,9 @@
 $config = \SimpleSAML\Configuration::getInstance();
 
 if (!array_key_exists('as', $_REQUEST)) {
-    $t = new SimpleSAML_XHTML_Template($config, 'core:authsource_list.tpl.php');
+    $t = new \SimpleSAML\XHTML\Template($config, 'core:authsource_list.tpl.php');
 
-    $t->data['sources'] = SimpleSAML_Auth_Source::getSources();
+    $t->data['sources'] = \SimpleSAML_Auth_Source::getSources();
     $t->show();
     exit();
 }
@@ -17,18 +17,18 @@ if (array_key_exists('logout', $_REQUEST)) {
     $as->logout($config->getBasePath().'logout.php');
 }
 
-if (array_key_exists(SimpleSAML_Auth_State::EXCEPTION_PARAM, $_REQUEST)) {
+if (array_key_exists(\SimpleSAML_Auth_State::EXCEPTION_PARAM, $_REQUEST)) {
     // This is just a simple example of an error
 
-    $state = SimpleSAML_Auth_State::loadExceptionState();
-    assert(array_key_exists(SimpleSAML_Auth_State::EXCEPTION_DATA, $state));
-    $e = $state[SimpleSAML_Auth_State::EXCEPTION_DATA];
+    $state = \SimpleSAML_Auth_State::loadExceptionState();
+    assert(array_key_exists(\SimpleSAML_Auth_State::EXCEPTION_DATA, $state));
+    $e = $state[\SimpleSAML_Auth_State::EXCEPTION_DATA];
 
     throw $e;
 }
 
 if (!$as->isAuthenticated()) {
-    $url = SimpleSAML\Module::getModuleURL('core/authenticate.php', array('as' => $asId));
+    $url = \SimpleSAML\Module::getModuleURL('core/authenticate.php', array('as' => $asId));
     $params = array(
         'ErrorURL' => $url,
         'ReturnTo' => $url,
@@ -39,7 +39,7 @@ if (!$as->isAuthenticated()) {
 $attributes = $as->getAttributes();
 $authData = $as->getAuthDataArray();
 
-$t = new SimpleSAML_XHTML_Template($config, 'status.php', 'attributes');
+$t = new \SimpleSAML\XHTML\Template($config, 'status.php', 'attributes');
 
 $t->data['header'] = '{status:header_saml20_sp}';
 $t->data['attributes'] = $attributes;
diff --git a/modules/core/www/cardinality_error.php b/modules/core/www/cardinality_error.php
index 2eb19e35483c7149209208ee659e932f1ebe2424..5d364aaa32b3352b306888374aa5c02b9facb0c4 100644
--- a/modules/core/www/cardinality_error.php
+++ b/modules/core/www/cardinality_error.php
@@ -16,7 +16,7 @@ $session = \SimpleSAML\Session::getSessionFromRequest();
     ' '.implode(',', array_keys($state['core:cardinality:errorAttributes'])));
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML_XHTML_Template($globalConfig, 'core:cardinality_error.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:cardinality_error.tpl.php');
 $t->data['cardinalityErrorAttributes'] = $state['core:cardinality:errorAttributes'];
 if (isset($state['Source']['auth'])) {
     $t->data['LogoutURL'] = \SimpleSAML\Module::getModuleURL('core/authenticate.php', array('as' => $state['Source']['auth']))."&logout";
diff --git a/modules/core/www/cleardiscochoices.php b/modules/core/www/cleardiscochoices.php
index 88a83be822415beedaef53aa43c59f7660f1ea5f..96c19d8418c883c2fa4b4fdc28d99c5a9b357ee4 100644
--- a/modules/core/www/cleardiscochoices.php
+++ b/modules/core/www/cleardiscochoices.php
@@ -23,7 +23,6 @@ foreach($_COOKIE as $cookieName => $value) {
     \SimpleSAML\Utils\HTTP::setCookie($cookieName, NULL, array('path' => $cookiePath, 'httponly' => FALSE), FALSE);
 }
 
-
 /* Find where we should go now. */
 if(array_key_exists('ReturnTo', $_REQUEST)) {
 	$returnTo = \SimpleSAML\Utils\HTTP::checkURLAllowed($_REQUEST['ReturnTo']);
diff --git a/modules/core/www/frontpage_auth.php b/modules/core/www/frontpage_auth.php
index 243221342cbb2d27a73f08722835d15a9895c137..7e3efb97987effea8767396acb73716d153f6829 100644
--- a/modules/core/www/frontpage_auth.php
+++ b/modules/core/www/frontpage_auth.php
@@ -1,15 +1,15 @@
 <?php
 
-// Load SimpleSAMLphp, configuration
+// Load SimpleSAMLphp configuration
 $config = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
 // Check if valid local session exists
 if ($config->getBoolean('admin.protectindexpage', false)) {
-    SimpleSAML\Utils\Auth::requireAdmin();
+    \SimpleSAML\Utils\Auth::requireAdmin();
 }
-$loginurl = SimpleSAML\Utils\Auth::getAdminLoginURL();
-$isadmin = SimpleSAML\Utils\Auth::isAdmin();
+$loginurl = \SimpleSAML\Utils\Auth::getAdminLoginURL();
+$isadmin = \SimpleSAML\Utils\Auth::isAdmin();
 
 $links = array();
 $links_welcome = array();
@@ -29,9 +29,9 @@ $allLinks = array(
 	'auth'       => &$links_auth,
 	'federation' => &$links_federation,
 );
-SimpleSAML\Module::callHooks('frontpage', $allLinks);
+\SimpleSAML\Module::callHooks('frontpage', $allLinks);
 
-$t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_auth.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_auth.tpl.php');
 $t->data['pageid'] = 'frontpage_auth';
 $t->data['isadmin'] = $isadmin;
 $t->data['loginurl'] = $loginurl;
diff --git a/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php
index b268297387caba8c11129d657a52921d4f2216e5..dd6cac3979a01b8d0eb06416a8392dec12526888 100644
--- a/modules/core/www/frontpage_config.php
+++ b/modules/core/www/frontpage_config.php
@@ -6,10 +6,10 @@ $session = \SimpleSAML\Session::getSessionFromRequest();
 
 // Check if valid local session exists.
 if ($config->getBoolean('admin.protectindexpage', false)) {
-    SimpleSAML\Utils\Auth::requireAdmin();
+    \SimpleSAML\Utils\Auth::requireAdmin();
 }
-$loginurl = SimpleSAML\Utils\Auth::getAdminLoginURL();
-$isadmin = SimpleSAML\Utils\Auth::isAdmin();
+$loginurl = \SimpleSAML\Utils\Auth::getAdminLoginURL();
+$isadmin = \SimpleSAML\Utils\Auth::isAdmin();
 
 
 $warnings = array();
@@ -52,7 +52,7 @@ $allLinks = array(
     'auth'       => &$links_auth,
    'federation' => &$links_federation,
 );
-SimpleSAML\Module::callHooks('frontpage', $allLinks);
+\SimpleSAML\Module::callHooks('frontpage', $allLinks);
 
 // Check for updates. Store the remote result in the session so we
 // don't need to fetch it on every access to this page.
@@ -106,10 +106,10 @@ $functionchecks = array(
     'session_start'  => array('optional', 'Session Extension (required if PHP sessions are used)'),
     'pdo_drivers'    => array('optional', 'PDO Extension (required if a database backend is used)'),
 );
-if (SimpleSAML\Module::isModuleEnabled('ldap')) {
+if (\SimpleSAML\Module::isModuleEnabled('ldap')) {
     $functionchecks['ldap_bind'] = array('optional', 'LDAP Extension (required if an LDAP backend is used)');
 }
-if (SimpleSAML\Module::isModuleEnabled('radius')) {
+if (\SimpleSAML\Module::isModuleEnabled('radius')) {
     $functionchecks['radius_auth_open'] = array('optional', 'Radius Extension (required if a Radius backend is used)');
 }
 
@@ -158,7 +158,7 @@ $funcmatrix[] = array(
     'enabled' => $password_ok
 );
 
-$t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_config.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_config.tpl.php');
 $t->data['pageid'] = 'frontpage_config';
 $t->data['isadmin'] = $isadmin;
 $t->data['loginurl'] = $loginurl;
diff --git a/modules/core/www/frontpage_federation.php b/modules/core/www/frontpage_federation.php
index 713aab5acfea48f467fa8a2417e8f58260bc0428..2e109c34041decc0d9e5bf7eca747d8e130ff5ef 100644
--- a/modules/core/www/frontpage_federation.php
+++ b/modules/core/www/frontpage_federation.php
@@ -1,15 +1,15 @@
 <?php
 
-// Load SimpleSAMLphp, configuration
+// Load SimpleSAMLphp configuration
 $config = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
 // Check if valid local session exists.
 if ($config->getBoolean('admin.protectindexpage', false)) {
-    SimpleSAML\Utils\Auth::requireAdmin();
+    \SimpleSAML\Utils\Auth::requireAdmin();
 }
-$loginurl = SimpleSAML\Utils\Auth::getAdminLoginURL();
-$isadmin = SimpleSAML\Utils\Auth::isAdmin();
+$loginurl = \SimpleSAML\Utils\Auth::getAdminLoginURL();
+$isadmin = \SimpleSAML\Utils\Auth::isAdmin();
 
 $links = array();
 $links_welcome = array();
@@ -37,14 +37,14 @@ $allLinks = array(
 	'auth'       => &$links_auth,
 	'federation' => &$links_federation,
 );
-SimpleSAML\Module::callHooks('frontpage', $allLinks);
+\SimpleSAML\Module::callHooks('frontpage', $allLinks);
 
 
 $metadataHosted = array();
-SimpleSAML\Module::callHooks('metadata_hosted', $metadataHosted);
+\SimpleSAML\Module::callHooks('metadata_hosted', $metadataHosted);
 
 
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
 $metaentries = array('hosted' => $metadataHosted, 'remote' => array() );
 
@@ -62,7 +62,7 @@ if ($config->getBoolean('enable.saml20-idp', FALSE) === true) {
 		if ($isadmin)
 			$metaentries['remote']['saml20-sp-remote'] = $metadata->getList('saml20-sp-remote');
 	} catch(Exception $e) {
-        SimpleSAML\Logger::error('Federation: Error loading saml20-idp: ' . $e->getMessage());
+        \SimpleSAML\Logger::error('Federation: Error loading saml20-idp: ' . $e->getMessage());
     }
 }
 if ($config->getBoolean('enable.shib13-idp', FALSE) === true) {
@@ -73,18 +73,18 @@ if ($config->getBoolean('enable.shib13-idp', FALSE) === true) {
 		if ($isadmin)
 			$metaentries['remote']['shib13-sp-remote'] = $metadata->getList('shib13-sp-remote');
 	} catch(Exception $e) {
-        SimpleSAML\Logger::error('Federation: Error loading shib13-idp: ' . $e->getMessage());
+        \SimpleSAML\Logger::error('Federation: Error loading shib13-idp: ' . $e->getMessage());
     }
 }
 if ($config->getBoolean('enable.adfs-idp', FALSE) === true) {
     try {
         $metaentries['hosted']['adfs-idp'] = $metadata->getMetaDataCurrent('adfs-idp-hosted');
-        $metaentries['hosted']['adfs-idp']['metadata-url'] = SimpleSAML\Module::getModuleURL('adfs/idp/metadata.php',
+        $metaentries['hosted']['adfs-idp']['metadata-url'] = \SimpleSAML\Module::getModuleURL('adfs/idp/metadata.php',
                                                                                              array('output' => 'xhtml'));
         if ($isadmin)
             $metaentries['remote']['adfs-sp-remote'] = $metadata->getList('adfs-sp-remote');
     } catch(Exception $e) {
-        SimpleSAML\Logger::error('Federation: Error loading adfs-idp: ' . $e->getMessage());
+        \SimpleSAML\Logger::error('Federation: Error loading adfs-idp: ' . $e->getMessage());
     }
 }
 
@@ -94,7 +94,7 @@ foreach ($metaentries['remote'] as $key => $value) {
 	}
 }
 
-$t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_federation.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_federation.tpl.php');
 
 # look up translated string
 $mtype = array(
diff --git a/modules/core/www/frontpage_welcome.php b/modules/core/www/frontpage_welcome.php
index 8ebb5e6f9bd8d59ef56733fd7966ce5c05d285bb..a9020fbe0ffac5a240df09c1f53873a489ebf5f6 100644
--- a/modules/core/www/frontpage_welcome.php
+++ b/modules/core/www/frontpage_welcome.php
@@ -9,8 +9,8 @@ $session = \SimpleSAML\Session::getSessionFromRequest();
 if ($config->getBoolean('admin.protectindexpage', false)) {
     SimpleSAML\Utils\Auth::requireAdmin();
 }
-$loginurl = SimpleSAML\Utils\Auth::getAdminLoginURL();
-$isadmin = SimpleSAML\Utils\Auth::isAdmin();
+$loginurl = \SimpleSAML\Utils\Auth::getAdminLoginURL();
+$isadmin = \SimpleSAML\Utils\Auth::isAdmin();
 
 $links = array();
 $links_welcome = array();
@@ -31,9 +31,9 @@ $links_welcome[] = array(
 	'text' => '{core:frontpage:doc_header}',
 );
 
-SimpleSAML\Module::callHooks('frontpage', $allLinks);
+\SimpleSAML\Module::callHooks('frontpage', $allLinks);
 
-$t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_welcome.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_welcome.tpl.php');
 $t->data['pageid'] = 'frontpage_welcome';
 $t->data['isadmin'] = $isadmin;
 $t->data['loginurl'] = $loginurl;
diff --git a/modules/core/www/idp/logout-iframe.php b/modules/core/www/idp/logout-iframe.php
index 71b908760a71e772271cf11c20e521b0fed49e6a..2463b50be5fe9138f60b33cba5d17e2f84fe8b2e 100644
--- a/modules/core/www/idp/logout-iframe.php
+++ b/modules/core/www/idp/logout-iframe.php
@@ -1,26 +1,26 @@
 <?php
 
 if (!isset($_REQUEST['id'])) {
-    throw new SimpleSAML_Error_BadRequest('Missing required parameter: id');
+    throw new \SimpleSAML_Error_BadRequest('Missing required parameter: id');
 }
 
 if (isset($_REQUEST['type'])) {
     $type = (string) $_REQUEST['type'];
     if (!in_array($type, array('init', 'js', 'nojs', 'embed'), true)) {
-        throw new SimpleSAML_Error_BadRequest('Invalid value for type.');
+        throw new \SimpleSAML_Error_BadRequest('Invalid value for type.');
     }
 } else {
     $type = 'init';
 }
 
 if ($type !== 'embed') {
-    SimpleSAML\Logger::stats('slo-iframe '.$type);
-    SimpleSAML_Stats::log('core:idp:logout-iframe:page', array('type' => $type));
+    \SimpleSAML\Logger::stats('slo-iframe '.$type);
+    \SimpleSAML_Stats::log('core:idp:logout-iframe:page', array('type' => $type));
 }
 
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['id'], 'core:Logout-IFrame');
-$idp = SimpleSAML_IdP::getByState($state);
-$mdh = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$state = \SimpleSAML_Auth_State::loadState($_REQUEST['id'], 'core:Logout-IFrame');
+$idp = \SimpleSAML_IdP::getByState($state);
+$mdh = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
 if ($type !== 'init') { // update association state
     foreach ($state['core:Logout-IFrame:Associations'] as $assocId => &$sp) {
@@ -74,7 +74,7 @@ foreach ($state['core:Logout-IFrame:Associations'] as $assocId => &$sp) {
         $assocIdP = SimpleSAML_IdP::getByState($sp);
         $url = call_user_func(array($sp['Handler'], 'getLogoutURL'), $assocIdP, $sp, null);
         $sp['core:Logout-IFrame:URL'] = $url;
-    } catch (Exception $e) {
+    } catch (\Exception $e) {
         $sp['core:Logout-IFrame:State'] = 'failed';
     }
 }
@@ -112,7 +112,7 @@ foreach ($state['core:Logout-IFrame:Associations'] as $association) {
     }
 }
 
-$id = SimpleSAML_Auth_State::saveState($state, 'core:Logout-IFrame');
+$id = \SimpleSAML_Auth_State::saveState($state, 'core:Logout-IFrame');
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 
 $template_id = 'core:logout-iframe.php';
@@ -120,7 +120,7 @@ if ($type === 'nojs') {
     $template_id = 'core:logout-iframe-wrapper.php';
 }
 
-$t = new SimpleSAML_XHTML_Template($globalConfig, $template_id);
+$t = new \SimpleSAML\XHTML\Template($globalConfig, $template_id);
 $t->data['auth_state'] = $id;
 /**
  * @deprecated The "id" variable will be removed. Please use "auth_state" instead.
diff --git a/modules/core/www/login-admin.php b/modules/core/www/login-admin.php
index 22bc7854aed50348332d85f3cc0aabd8cb9a7ff8..4d8e6c8517038e417f0e948abfa6ed264b90dfcd 100644
--- a/modules/core/www/login-admin.php
+++ b/modules/core/www/login-admin.php
@@ -4,10 +4,10 @@
  */
 
 if (!array_key_exists('ReturnTo', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing ReturnTo parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing ReturnTo parameter.');
 }
 
-SimpleSAML\Utils\Auth::requireAdmin();
+\SimpleSAML\Utils\Auth::requireAdmin();
 
 \SimpleSAML\Utils\HTTP::redirectUntrustedURL($_REQUEST['ReturnTo']);
 
diff --git a/modules/core/www/loginuserpass.php b/modules/core/www/loginuserpass.php
index 2469c222076b9a1a4fd99fe3734ac93034ee2853..70dd0d15002b6ff2cc723b0d366e5321f283159c 100644
--- a/modules/core/www/loginuserpass.php
+++ b/modules/core/www/loginuserpass.php
@@ -73,7 +73,7 @@ if (!empty($_REQUEST['username']) || !empty($password)) {
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'core:loginuserpass.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:loginuserpass.php');
 $t->data['stateparams'] = array('AuthState' => $authStateId);
 if (array_key_exists('forcedUsername', $state)) {
 	$t->data['username'] = $state['forcedUsername'];
diff --git a/modules/core/www/loginuserpassorg.php b/modules/core/www/loginuserpassorg.php
index 07a89859cccf1f0ae091ec6740dbb2f60a42fed9..90f6e46afacf237bb8294a9215a693e9c830a2cf 100644
--- a/modules/core/www/loginuserpassorg.php
+++ b/modules/core/www/loginuserpassorg.php
@@ -11,17 +11,17 @@
 
 // Retrieve the authentication state
 if (!array_key_exists('AuthState', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing AuthState parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing AuthState parameter.');
 }
 $authStateId = $_REQUEST['AuthState'];
-$state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_core_Auth_UserPassOrgBase::STAGEID);
+$state = \SimpleSAML_Auth_State::loadState($authStateId, sspmod_core_Auth_UserPassOrgBase::STAGEID);
 
-$source = SimpleSAML_Auth_Source::getById($state[sspmod_core_Auth_UserPassOrgBase::AUTHID]);
+$source = \SimpleSAML_Auth_Source::getById($state[sspmod_core_Auth_UserPassOrgBase::AUTHID]);
 if ($source === NULL) {
 	throw new Exception('Could not find authentication source with id ' . $state[sspmod_core_Auth_UserPassOrgBase::AUTHID]);
 }
 
-$organizations = sspmod_core_Auth_UserPassOrgBase::listOrganizations($authStateId);
+$organizations = \sspmod_core_Auth_UserPassOrgBase::listOrganizations($authStateId);
 
 if (array_key_exists('username', $_REQUEST)) {
 	$username = $_REQUEST['username'];
@@ -61,7 +61,7 @@ if ($organizations === NULL || !empty($organization)) {
 		}
 
 		try {
-			sspmod_core_Auth_UserPassOrgBase::handleLogin($authStateId, $username, $password, $organization);
+			\sspmod_core_Auth_UserPassOrgBase::handleLogin($authStateId, $username, $password, $organization);
 		} catch (SimpleSAML_Error_Error $e) {
 			// Login failed. Extract error code and parameters, to display the error
 			$errorCode = $e->getErrorCode();
@@ -71,7 +71,7 @@ if ($organizations === NULL || !empty($organization)) {
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'core:loginuserpass.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:loginuserpass.php');
 $t->data['stateparams'] = array('AuthState' => $authStateId);
 $t->data['username'] = $username;
 $t->data['forceUsername'] = FALSE;
@@ -81,7 +81,7 @@ $t->data['rememberMeEnabled'] = false;
 $t->data['rememberMeChecked'] = false;
 if (isset($_COOKIE[$source->getAuthId() . '-username'])) $t->data['rememberUsernameChecked'] = TRUE;
 $t->data['errorcode'] = $errorCode;
-$t->data['errorcodes'] = SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
+$t->data['errorcodes'] = \SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
 $t->data['errorparams'] = $errorParams;
 
 if ($organizations !== NULL) {
diff --git a/modules/core/www/no_cookie.php b/modules/core/www/no_cookie.php
index 76ddd662d7198320b68f8a9574c9f294880e57f2..8ad2e3c83ea97ad30d35bde4ada7914afd5229fd 100644
--- a/modules/core/www/no_cookie.php
+++ b/modules/core/www/no_cookie.php
@@ -8,6 +8,6 @@ if (isset($_REQUEST['retryURL'])) {
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'core:no_cookie.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:no_cookie.tpl.php');
 $t->data['retryURL'] = $retryURL;
 $t->show();
diff --git a/modules/core/www/postredirect.php b/modules/core/www/postredirect.php
index 06d52ce4b36181c0d9be775356b14bb240138bf8..00cb8a0885161f5e645498b9d251b0371ec0c0f5 100644
--- a/modules/core/www/postredirect.php
+++ b/modules/core/www/postredirect.php
@@ -13,18 +13,18 @@ if (array_key_exists('RedirId', $_REQUEST)) {
 	$encData = base64_decode($_REQUEST['RedirInfo']);
 
 	if (empty($encData)) {
-		throw new SimpleSAML_Error_BadRequest('Invalid RedirInfo data.');
+		throw new \SimpleSAML_Error_BadRequest('Invalid RedirInfo data.');
 	}
 
-	list($sessionId, $postId) = explode(':', SimpleSAML\Utils\Crypto::aesDecrypt($encData));
+	list($sessionId, $postId) = explode(':', \SimpleSAML\Utils\Crypto::aesDecrypt($encData));
 
 	if (empty($sessionId) || empty($postId)) {
-		throw new SimpleSAML_Error_BadRequest('Invalid session info data.');
+		throw new \SimpleSAML_Error_BadRequest('Invalid session info data.');
 	}
 
 	$session = \SimpleSAML\Session::getSession($sessionId);
 } else {
-	throw new SimpleSAML_Error_BadRequest('Missing redirection info parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing redirection info parameter.');
 }
 
 if ($session === NULL) {
@@ -45,7 +45,7 @@ assert(array_key_exists('url', $postData));
 assert(array_key_exists('post', $postData));
 
 $config = \SimpleSAML\Configuration::getInstance();
-$template = new SimpleSAML_XHTML_Template($config, 'post.php');
+$template = new \SimpleSAML\XHTML\Template($config, 'post.php');
 $template->data['destination'] = $postData['url'];
 $template->data['post'] = $postData['post'];
 $template->show();
diff --git a/modules/core/www/short_sso_interval.php b/modules/core/www/short_sso_interval.php
index ce61bdfe69d9cce58eaabb855d97c77864bde40e..983a4d93077666b8f7c9332be102b5a6a9081344 100644
--- a/modules/core/www/short_sso_interval.php
+++ b/modules/core/www/short_sso_interval.php
@@ -7,20 +7,20 @@
  */
 
 if (!array_key_exists('StateId', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = SimpleSAML_Auth_State::loadState($id, 'core:short_sso_interval');
+$state = \SimpleSAML_Auth_State::loadState($id, 'core:short_sso_interval');
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
 if (array_key_exists('continue', $_REQUEST)) {
 	// The user has pressed the continue/retry-button
-	SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+	\SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'core:short_sso_interval.php');
-$t->data['target'] = SimpleSAML\Module::getModuleURL('core/short_sso_interval.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:short_sso_interval.php');
+$t->data['target'] = \SimpleSAML\Module::getModuleURL('core/short_sso_interval.php');
 $t->data['params'] = array('StateId' => $id);
 $t->data['trackId'] = $session->getTrackID();
 $t->show();
diff --git a/modules/core/www/show_metadata.php b/modules/core/www/show_metadata.php
index d1a65b1aee69588744886429a0a5e5bb59ee74b7..d91af1d413b049fa7368242da0c73f4dcefe441e 100644
--- a/modules/core/www/show_metadata.php
+++ b/modules/core/www/show_metadata.php
@@ -4,7 +4,7 @@
 $config = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
-SimpleSAML\Utils\Auth::requireAdmin();
+\SimpleSAML\Utils\Auth::requireAdmin();
 
 if (!array_key_exists('entityid', $_REQUEST)) {
     throw new Exception('required parameter [entityid] missing');
@@ -20,15 +20,15 @@ if (!in_array(
     throw new Exception('Invalid set');
 }
 
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
 $m = $metadata->getMetadata($_REQUEST['entityid'], $_REQUEST['set']);
 
-$t = new SimpleSAML_XHTML_Template($config, 'core:show_metadata.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:show_metadata.tpl.php');
 $t->data['clipboard.js'] = true;
 $t->data['pageid'] = 'show_metadata';
 $t->data['header'] = 'SimpleSAMLphp Show Metadata';
-$t->data['backlink'] = SimpleSAML\Module::getModuleURL('core/frontpage_federation.php');
+$t->data['backlink'] = \SimpleSAML\Module::getModuleURL('core/frontpage_federation.php');
 $t->data['m'] = $m;
 
 $t->show();
diff --git a/modules/cron/www/cron.php b/modules/cron/www/cron.php
index d8463d74559abfc9196c6dfa1fb2727caaa78a10..69329b977a6018af9b73fec1b2e57e169b43b0e9 100644
--- a/modules/cron/www/cron.php
+++ b/modules/cron/www/cron.php
@@ -5,18 +5,17 @@ $cronconfig = \SimpleSAML\Configuration::getConfig('module_cron.php');
 
 if (!is_null($cronconfig->getValue('key'))) {
 	if ($_REQUEST['key'] !== $cronconfig->getValue('key')) {
-		SimpleSAML\Logger::error('Cron - Wrong key provided. Cron will not run.');
+		\SimpleSAML\Logger::error('Cron - Wrong key provided. Cron will not run.');
 		exit;
 	}
 }
 
-$cron = new SimpleSAML\Module\cron\Cron();
+$cron = new \SimpleSAML\Module\cron\Cron();
 if (!$cron->isValidTag($_REQUEST['tag'])) {
     SimpleSAML\Logger::error('Cron - Illegal tag [' . $_REQUEST['tag'] . '].');
     exit;
 }
 
-
 $url = \SimpleSAML\Utils\HTTP::getSelfURL();
 $time = date(DATE_RFC822);
 
@@ -24,7 +23,6 @@ $croninfo = $cron->runTag($_REQUEST['tag']);
 $summary = $croninfo['summary'];
 
 if ($cronconfig->getValue('sendemail', TRUE) && count($summary) > 0) {
-
 	$message = '<h1>Cron report</h1><p>Cron ran at ' . $time . '</p>' .
 		'<p>URL: <tt>' . $url . '</tt></p>' .
 		'<p>Tag: ' . $croninfo['tag'] . "</p>\n\n" .
@@ -32,18 +30,17 @@ if ($cronconfig->getValue('sendemail', TRUE) && count($summary) > 0) {
 
 	$toaddress = $config->getString('technicalcontact_email', 'na@example.org');
 	if($toaddress == 'na@example.org') {
-		SimpleSAML\Logger::error('Cron - Could not send email. [technicalcontact_email] not set in config.');
+		\SimpleSAML\Logger::error('Cron - Could not send email. [technicalcontact_email] not set in config.');
 	} else {
 		// Use $toaddress for both TO and FROM
-		$email = new SimpleSAML_XHTML_EMail($toaddress, 'SimpleSAMLphp cron report', $toaddress);
+		$email = new \SimpleSAML\XHTML\EMail($toaddress, 'SimpleSAMLphp cron report', $toaddress);
 		$email->setBody($message);
 		$email->send();
 	}
-	
 }
 
 if (isset($_REQUEST['output']) && $_REQUEST['output'] == "xhtml") {
-	$t = new SimpleSAML_XHTML_Template($config, 'cron:croninfo-result.php','cron:cron');
+	$t = new \SimpleSAML\XHTML\Template($config, 'cron:croninfo-result.php','cron:cron');
 	$t->data['tag'] = $croninfo['tag'];
 	$t->data['time'] = $time;
 	$t->data['url'] = $url;
diff --git a/modules/cron/www/croninfo.php b/modules/cron/www/croninfo.php
index 643d245027f8a02b375e5c70ff5a2a9b3761eeef..3e646cc6ccca52d6b14e545aa2c624c9685aa20e 100644
--- a/modules/cron/www/croninfo.php
+++ b/modules/cron/www/croninfo.php
@@ -4,14 +4,14 @@
  * The _include script registers a autoloader for the SimpleSAMLphp libraries. It also
  * initializes the SimpleSAMLphp config class with the correct path.
  */
-require_once('_include.php');
 
+require_once('_include.php');
 
-// Load SimpleSAMLphp, configuration and metadata
+// Load SimpleSAMLphp configuration and metadata
 $config = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
-SimpleSAML\Utils\Auth::requireAdmin();
+\SimpleSAML\Utils\Auth::requireAdmin();
 
 $cronconfig = \SimpleSAML\Configuration::getConfig('module_cron.php');
 
@@ -28,14 +28,12 @@ $def = array(
 $urls = array();
 foreach ($tags AS $tag) {
 	$urls[] = array(
-		'href' => SimpleSAML\Module::getModuleURL('cron/cron.php', array('key' => $key, 'tag' => $tag)),
+		'href' => \SimpleSAML\Module::getModuleURL('cron/cron.php', array('key' => $key, 'tag' => $tag)),
 		'tag' => $tag,
 		'int' => (array_key_exists($tag, $def) ? $def[$tag] : $def['default']),
 	);
 }
 
-
-
-$t = new SimpleSAML_XHTML_Template($config, 'cron:croninfo.tpl.php', 'cron:cron');
+$t = new \SimpleSAML\XHTML\Template($config, 'cron:croninfo.tpl.php', 'cron:cron');
 $t->data['urls'] = $urls;
 $t->show();
diff --git a/modules/discopower/lib/PowerIdPDisco.php b/modules/discopower/lib/PowerIdPDisco.php
index be41e6f344c5a89142cd563a259e0dfe67753e4b..31452d482e454627b73de559da6080e62d883fd4 100644
--- a/modules/discopower/lib/PowerIdPDisco.php
+++ b/modules/discopower/lib/PowerIdPDisco.php
@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * This class implements a generic IdP discovery service, for use in various IdP discovery service pages. This should
  * reduce code duplication.
@@ -10,10 +9,9 @@
  * @author Andreas Ă…kre Solberg <andreas@uninett.no>, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco
-{
-
 
+class sspmod_discopower_PowerIdPDisco extends \SimpleSAML\XHTML\IdPDisco
+{
     /**
      * The configuration for this instance.
      *
@@ -253,7 +251,7 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco
             }
         }
 
-        $t = new SimpleSAML_XHTML_Template($this->config, 'discopower:disco.tpl.php', 'disco');
+        $t = new \SimpleSAML\XHTML\Template($this->config, 'discopower:disco.tpl.php', 'disco');
         $discoPowerTabs = array(
             'denmark' => $t->noop('{discopower:tabs:denmark}'),
             'edugain' => $t->noop('{discopower:tabs:edugain}'),
diff --git a/modules/expirycheck/www/about2expire.php b/modules/expirycheck/www/about2expire.php
index f85a09d9abb9a508fc4e19e9c45a8a672891ec14..ada7043c713db54fc1172c7fb22404de22f86efb 100644
--- a/modules/expirycheck/www/about2expire.php
+++ b/modules/expirycheck/www/about2expire.php
@@ -6,23 +6,23 @@
  * @package SimpleSAMLphp
  */
 
-SimpleSAML\Logger::info('expirycheck - User has been warned that NetID is near to expirational date.');
+\SimpleSAML\Logger::info('expirycheck - User has been warned that NetID is near to expirational date.');
 
 if (!array_key_exists('StateId', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = SimpleSAML_Auth_State::loadState($id, 'expirywarning:about2expire');
+$state = \SimpleSAML_Auth_State::loadState($id, 'expirywarning:about2expire');
 
 if (array_key_exists('yes', $_REQUEST)) {
 	// The user has pressed the yes-button
-	SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+	\SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'expirycheck:about2expire.php');
-$t->data['yesTarget'] = SimpleSAML\Module::getModuleURL('expirycheck/about2expire.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'expirycheck:about2expire.php');
+$t->data['yesTarget'] = \SimpleSAML\Module::getModuleURL('expirycheck/about2expire.php');
 $t->data['yesData'] = array('StateId' => $id);
 $t->data['daysleft'] = $state['daysleft'];
 $t->data['expireOnDate'] = $state['expireOnDate'];
diff --git a/modules/expirycheck/www/expired.php b/modules/expirycheck/www/expired.php
index 225406910e3ca2575b1cc7a0df3bd75af73e25c7..33fe530c4a06e9625c011551189d1c20408119eb 100644
--- a/modules/expirycheck/www/expired.php
+++ b/modules/expirycheck/www/expired.php
@@ -6,16 +6,16 @@
  * @package SimpleSAMLphp
  */
 
-SimpleSAML\Logger::info('expirycheck - User has been warned that NetID is near to expirational date.');
+\SimpleSAML\Logger::info('expirycheck - User has been warned that NetID is near to expirational date.');
 
 if (!array_key_exists('StateId', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['StateId'], 'expirywarning:expired');
+$state = \SimpleSAML_Auth_State::loadState($_REQUEST['StateId'], 'expirywarning:expired');
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'expirycheck:expired.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'expirycheck:expired.php');
 $t->data['expireOnDate'] = $state['expireOnDate'];
 $t->data['netId'] = $state['netId'];
 $t->show();
diff --git a/modules/memcacheMonitor/www/memcachestat.php b/modules/memcacheMonitor/www/memcachestat.php
index 5e9caa8f47248be080b73c4bf1f7acfa50438d91..452a6fd6a942a6647188e7d6e41454a332bfa461 100644
--- a/modules/memcacheMonitor/www/memcachestat.php
+++ b/modules/memcacheMonitor/www/memcachestat.php
@@ -12,9 +12,7 @@ function hours($input) {
 	
 }
 
-
 function humanreadable($input) {
-	 
 	$output = "";
 	$input = abs($input);
 	
@@ -69,14 +67,10 @@ function humanreadable($input) {
 	return $output;
 }
 
-
-
-
 $config = \SimpleSAML\Configuration::getInstance();
 
 // Make sure that the user has admin access rights
-SimpleSAML\Utils\Auth::requireAdmin();
-
+\SimpleSAML\Utils\Auth::requireAdmin();
 
 $formats = array(
 	'bytes' => 'humanreadable',
@@ -87,7 +81,7 @@ $formats = array(
 	'uptime' => 'hours',
 );
 
-$statsraw = SimpleSAML_Memcache::getStats();
+$statsraw = \SimpleSAML_Memcache::getStats();
 
 $stats = $statsraw;
 
@@ -101,7 +95,7 @@ foreach($stats AS $key => &$entry) {
 
 }
 
-$t = new SimpleSAML_XHTML_Template($config, 'memcacheMonitor:memcachestat.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'memcacheMonitor:memcachestat.tpl.php');
 $rowTitles = array(
     'accepting_conns' => \SimpleSAML\Locale\Translate::noop('{memcacheMonitor:memcachestat:accepting_conns}'),
     'auth_cmds' => \SimpleSAML\Locale\Translate::noop('{memcacheMonitor:memcachestat:auth_cmds}'),
diff --git a/modules/metarefresh/www/fetch.php b/modules/metarefresh/www/fetch.php
index 44d9b110e58fed57fe41d5b9113c6a0f86a52dc4..ee7b85c87219952e9c404c6d7f9186b947bf2a9c 100644
--- a/modules/metarefresh/www/fetch.php
+++ b/modules/metarefresh/www/fetch.php
@@ -3,20 +3,18 @@
 $config = \SimpleSAML\Configuration::getInstance();
 $mconfig = \SimpleSAML\Configuration::getOptionalConfig('config-metarefresh.php');
 
-SimpleSAML\Utils\Auth::requireAdmin();
+\SimpleSAML\Utils\Auth::requireAdmin();
 
-SimpleSAML\Logger::setCaptureLog(TRUE);
+\SimpleSAML\Logger::setCaptureLog(TRUE);
 
 
 $sets = $mconfig->getConfigList('sets', array());
 
 foreach ($sets AS $setkey => $set) {
 
-	SimpleSAML\Logger::info('[metarefresh]: Executing set [' . $setkey . ']');
+	\SimpleSAML\Logger::info('[metarefresh]: Executing set [' . $setkey . ']');
 
 	try {
-		
-
 		$expireAfter = $set->getInteger('expireAfter', NULL);
 		if ($expireAfter !== NULL) {
 			$expire = time() + $expireAfter;
@@ -63,7 +61,7 @@ foreach ($sets AS $setkey => $set) {
 				$source['whitelist'] = $whitelist;
 			}
 
-			SimpleSAML\Logger::debug('[metarefresh]: In set [' . $setkey . '] loading source ['  . $source['src'] . ']');
+			\SimpleSAML\Logger::debug('[metarefresh]: In set [' . $setkey . '] loading source ['  . $source['src'] . ']');
 			$metaloader->loadSource($source);
 		}
 
@@ -79,16 +77,14 @@ foreach ($sets AS $setkey => $set) {
 				$metaloader->writeMetadataSerialize($outputDir);
 				break;
 		}
-	} catch (Exception $e) {
+	} catch (\Exception $e) {
 		$e = SimpleSAML_Error_Exception::fromException($e);
 		$e->logWarning();
 	}
-	
-
 }
 
-$logentries = SimpleSAML\Logger::getCapturedLog();
+$logentries = \SimpleSAML\Logger::getCapturedLog();
 
-$t = new SimpleSAML_XHTML_Template($config, 'metarefresh:fetch.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'metarefresh:fetch.tpl.php');
 $t->data['logentries'] = $logentries;
 $t->show();
diff --git a/modules/multiauth/www/selectsource.php b/modules/multiauth/www/selectsource.php
index 791db0227cc92f78cc43baf52a859d3aaa4a0b5c..ff743d4880076c992a081a84a9ec9ab2ec174bfe 100644
--- a/modules/multiauth/www/selectsource.php
+++ b/modules/multiauth/www/selectsource.php
@@ -12,14 +12,14 @@
 
 // Retrieve the authentication state
 if (!array_key_exists('AuthState', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing AuthState parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing AuthState parameter.');
 }
 $authStateId = $_REQUEST['AuthState'];
-$state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_multiauth_Auth_Source_MultiAuth::STAGEID);
+$state = \SimpleSAML_Auth_State::loadState($authStateId, sspmod_multiauth_Auth_Source_MultiAuth::STAGEID);
 
 if (array_key_exists("SimpleSAML_Auth_Source.id", $state)) {
 	$authId = $state["SimpleSAML_Auth_Source.id"];
-	$as = SimpleSAML_Auth_Source::getById($authId);
+	$as = \SimpleSAML_Auth_Source::getById($authId);
 } else {
 	$as = NULL;
 }
@@ -39,18 +39,18 @@ if ($source !== NULL) {
 	if ($as !== NULL) {
 		$as->setPreviousSource($source);
 	}
-	sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state);
+	\sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state);
 }
 
 if (array_key_exists('multiauth:preselect', $state)) {
 	$source = $state['multiauth:preselect'];
-	sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state);
+	\sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state);
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'multiauth:selectsource.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'multiauth:selectsource.php');
 $t->data['authstate'] = $authStateId;
-$t->data['sources'] = $state[sspmod_multiauth_Auth_Source_MultiAuth::SOURCESID];
+$t->data['sources'] = $state[\sspmod_multiauth_Auth_Source_MultiAuth::SOURCESID];
 if ($as !== NULL) {
 	$t->data['preferred'] = $as->getPreviousSource();
 } else {
diff --git a/modules/negotiate/www/disable.php b/modules/negotiate/www/disable.php
index ba5d7834af55b33d735e644dd1ac9d2fa0de9424..fafe79a067aebf3aa2797adb4f60f6b3c348b74d 100644
--- a/modules/negotiate/www/disable.php
+++ b/modules/negotiate/www/disable.php
@@ -18,6 +18,6 @@ $params = array(
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 $session->setData('negotiate:disable', 'session', FALSE, 24*60*60);
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'negotiate:disable.php');
-$t->data['url'] = SimpleSAML\Module::getModuleURL('negotiate/enable.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'negotiate:disable.php');
+$t->data['url'] = \SimpleSAML\Module::getModuleURL('negotiate/enable.php');
 $t->show();
diff --git a/modules/negotiate/www/enable.php b/modules/negotiate/www/enable.php
index 926bb31865b2df6276876d88a9f885bb5eb817c2..293b7b97c19882dfcac12258dc2f4fa03ea0bec9 100644
--- a/modules/negotiate/www/enable.php
+++ b/modules/negotiate/www/enable.php
@@ -17,6 +17,6 @@ $params = array(
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 $session->setData('negotiate:disable', 'session', FALSE, 24*60*60);
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'negotiate:enable.php');
-$t->data['url'] = SimpleSAML\Module::getModuleURL('negotiate/disable.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'negotiate:enable.php');
+$t->data['url'] = \SimpleSAML\Module::getModuleURL('negotiate/disable.php');
 $t->show();
diff --git a/modules/oauth/www/registry.edit.php b/modules/oauth/www/registry.edit.php
index 32cf7bb11557827df8b1788ee8cc1b4ec41afe7f..1e750d2edb1859e0e6dc33efb238159c9972a31a 100644
--- a/modules/oauth/www/registry.edit.php
+++ b/modules/oauth/www/registry.edit.php
@@ -5,7 +5,7 @@ $config = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 $oauthconfig = \SimpleSAML\Configuration::getOptionalConfig('module_oauth.php');
 
-$store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
+$store = new \sspmod_core_Storage_SQLPermanentStorage('oauth');
 
 $authsource = "admin";	// force admin to authenticate as registry maintainer
 $useridattr = $oauthconfig->getValue('useridattr', 'user');
@@ -17,15 +17,15 @@ if ($session->isValid($authsource)) {
 		throw new Exception('User ID is missing');
 	$userid = $attributes[$useridattr][0];
 } else {
-	$as = SimpleSAML_Auth_Source::getById($authsource);
+	$as = \SimpleSAML_Auth_Source::getById($authsource);
 	$as->initLogin(\SimpleSAML\Utils\HTTP::getSelfURL());
 }
 
 function requireOwnership($entry, $userid) {
 	if (!isset($entry['owner']))
-		throw new Exception('OAuth Consumer has no owner. Which means no one is granted access, not even you.');
+		throw new \Exception('OAuth Consumer has no owner. Which means no one is granted access, not even you.');
 	if ($entry['owner'] !== $userid) 
-		throw new Exception('OAuth Consumer has an owner that is not equal to your userid, hence you are not granted access.');
+		throw new \Exception('OAuth Consumer has an owner that is not equal to your userid, hence you are not granted access.');
 }
 
 if (array_key_exists('editkey', $_REQUEST)) {
@@ -36,15 +36,13 @@ if (array_key_exists('editkey', $_REQUEST)) {
 } else {
 	$entry = array(
 		'owner' => $userid,
-		'key' => SimpleSAML\Utils\Random::generateID(),
-		'secret' => SimpleSAML\Utils\Random::generateID(),
+		'key' => \SimpleSAML\Utils\Random::generateID(),
+		'secret' => \SimpleSAML\Utils\Random::generateID(),
 	);
 }
 
-
 $editor = new sspmod_oauth_Registry();
 
-
 if (isset($_POST['submit'])) {
 	$editor->checkForm($_POST);
 
@@ -54,7 +52,7 @@ if (isset($_POST['submit'])) {
 
 	$store->set('consumers', $entry['key'], '', $entry);
 	
-	$template = new SimpleSAML_XHTML_Template($config, 'oauth:registry.saved.php');
+	$template = new \SimpleSAML\XHTML\Template($config, 'oauth:registry.saved.php');
 	$template->data['entry'] = $entry;
 	$template->show();
 	exit;
@@ -62,7 +60,7 @@ if (isset($_POST['submit'])) {
 
 $form = $editor->metaToForm($entry);
 
-$template = new SimpleSAML_XHTML_Template($config, 'oauth:registry.edit.tpl.php');
+$template = new \SimpleSAML\XHTML\Template($config, 'oauth:registry.edit.tpl.php');
 $template->data['form'] = $form;
 $template->show();
 
diff --git a/modules/oauth/www/registry.php b/modules/oauth/www/registry.php
index 62b7e3ee8f31801796b8e3722e14ee425d439bc7..c13ce18a4f604c81a9fac0cb1f9d10dbbb9e5a53 100644
--- a/modules/oauth/www/registry.php
+++ b/modules/oauth/www/registry.php
@@ -5,7 +5,7 @@ $config = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 $oauthconfig = \SimpleSAML\Configuration::getOptionalConfig('module_oauth.php');
 
-$store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
+$store = new \sspmod_core_Storage_SQLPermanentStorage('oauth');
 
 $authsource = "admin";	// force admin to authenticate as registry maintainer
 $useridattr = $oauthconfig->getValue('useridattr', 'user');
@@ -17,7 +17,7 @@ if ($session->isValid($authsource)) {
 		throw new Exception('User ID is missing');
 	$userid = $attributes[$useridattr][0];
 } else {
-	$as = SimpleSAML_Auth_Source::getById($authsource);
+	$as = \SimpleSAML_Auth_Source::getById($authsource);
 	$as->initLogin(\SimpleSAML\Utils\HTTP::getSelfURL());
 }
 
@@ -51,7 +51,7 @@ foreach($list AS $listitem) {
 	$slist['others'][] = $listitem;
 }
 
-$template = new SimpleSAML_XHTML_Template($config, 'oauth:registry.list.php');
+$template = new \SimpleSAML\XHTML\Template($config, 'oauth:registry.list.php');
 $template->data['entries'] = $slist;
 $template->data['userid'] = $userid;
 $template->show();
diff --git a/modules/preprodwarning/www/showwarning.php b/modules/preprodwarning/www/showwarning.php
index 4d5fcf375784ff3d01d024a7e403d80ca9f6085c..77c5e98bcbebdac3ea0c3154f0343c47587f9f58 100644
--- a/modules/preprodwarning/www/showwarning.php
+++ b/modules/preprodwarning/www/showwarning.php
@@ -7,26 +7,26 @@
  * @package SimpleSAMLphp
  */
 
-SimpleSAML\Logger::info('PreProdWarning - Showing warning to user');
+\SimpleSAML\Logger::info('PreProdWarning - Showing warning to user');
 
 if (!array_key_exists('StateId', $_REQUEST)) {
-	throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
+	throw new \SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = SimpleSAML_Auth_State::loadState($id, 'warning:request');
+$state = \SimpleSAML_Auth_State::loadState($id, 'warning:request');
 
 
 if (array_key_exists('yes', $_REQUEST)) {
 	// The user has pressed the yes-button
 
-	SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+	\SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
 }
 
 
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'preprodwarning:warning.php');
-$t->data['yesTarget'] = SimpleSAML\Module::getModuleURL('preprodwarning/showwarning.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'preprodwarning:warning.php');
+$t->data['yesTarget'] = \SimpleSAML\Module::getModuleURL('preprodwarning/showwarning.php');
 $t->data['yesData'] = array('StateId' => $id);
 $t->show();
diff --git a/modules/saml/templates/proxy/invalid_session.php b/modules/saml/templates/proxy/invalid_session.php
index 1131379988f3a9954594674d5d57a72d9fb52ef6..94d63f9cdaa4cf5f510cc01d7c14bf8a427c3536 100644
--- a/modules/saml/templates/proxy/invalid_session.php
+++ b/modules/saml/templates/proxy/invalid_session.php
@@ -2,7 +2,7 @@
 /**
  * Template to ask a user whether to logout because of a reauthentication or not.
  *
- * @var SimpleSAML_XHTML_Template $this
+ * @var \SimpleSAML\XHTML\Template $this
  *
  * @author Jaime PĂ©rez Crespo, UNINETT AS <jaime.perez@uninett.no>
  *
diff --git a/modules/saml/www/disco.php b/modules/saml/www/disco.php
index 1f3bac0857692bcd0760b3bb0bf3ac89ce519fe5..8a229f9f37ca0a7b6b69316922ca68f272938fad 100644
--- a/modules/saml/www/disco.php
+++ b/modules/saml/www/disco.php
@@ -4,5 +4,5 @@
  * Built-in IdP discovery service.
  */
 
-$discoHandler = new SimpleSAML_XHTML_IdPDisco(array('saml20-idp-remote', 'shib13-idp-remote'), 'saml');
+$discoHandler = new \impleSAML\XHTML\IdPDisco(array('saml20-idp-remote', 'shib13-idp-remote'), 'saml');
 $discoHandler->handleRequest();
diff --git a/modules/saml/www/proxy/invalid_session.php b/modules/saml/www/proxy/invalid_session.php
index 30616af131e1a37471c1ed0913e7c17174409283..95ba63d9a7e7e103861183d7dc67e6e4daaa7d18 100644
--- a/modules/saml/www/proxy/invalid_session.php
+++ b/modules/saml/www/proxy/invalid_session.php
@@ -11,24 +11,24 @@
 
 // retrieve the authentication state
 if (!array_key_exists('AuthState', $_REQUEST)) {
-    throw new SimpleSAML_Error_BadRequest('Missing mandatory parameter: AuthState');
+    throw new \SimpleSAML_Error_BadRequest('Missing mandatory parameter: AuthState');
 }
 
 try {
     // try to get the state
-    $state = SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], 'saml:proxy:invalid_idp');
-} catch (Exception $e) {
+    $state = \SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], 'saml:proxy:invalid_idp');
+} catch (\Exception $e) {
     // the user probably hit the back button after starting the logout, try to recover the state with another stage
-    $state = SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], 'core:Logout:afterbridge');
+    $state = \SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], 'core:Logout:afterbridge');
 
     // success! Try to continue with reauthentication, since we no longer have a valid session here
-    $idp = SimpleSAML_IdP::getById($state['core:IdP']);
-    sspmod_saml_Auth_Source_SP::reauthPostLogout($idp, $state);
+    $idp = \SimpleSAML_IdP::getById($state['core:IdP']);
+    \sspmod_saml_Auth_Source_SP::reauthPostLogout($idp, $state);
 }
 
 if (isset($_POST['cancel'])) {
     // the user does not want to logout, cancel login
-    SimpleSAML_Auth_State::throwException(
+    \SimpleSAML_Auth_State::throwException(
         $state,
         new \SimpleSAML\Module\saml\Error\NoAvailableIDP(
             \SAML2\Constants::STATUS_RESPONDER,
@@ -39,13 +39,13 @@ if (isset($_POST['cancel'])) {
 
 if (isset($_POST['continue'])) {
     // log the user out before being able to login again
-    $as = SimpleSAML_Auth_Source::getById($state['saml:sp:AuthId'], 'sspmod_saml_Auth_Source_SP');
-    /** @var sspmod_saml_Auth_Source_SP $as */
+    $as = \SimpleSAML_Auth_Source::getById($state['saml:sp:AuthId'], 'sspmod_saml_Auth_Source_SP');
+    /** @var \sspmod_saml_Auth_Source_SP $as */
     $as->reauthLogout($state);
 }
 
 $cfg = \SimpleSAML\Configuration::getInstance();
-$template = new SimpleSAML_XHTML_Template($cfg, 'saml:proxy/invalid_session.php');
+$template = new \SimpleSAML\XHTML\Template($cfg, 'saml:proxy/invalid_session.php');
 $translator = $template->getTranslator();
 $template->data['AuthState'] = (string)$_REQUEST['AuthState'];
 
diff --git a/modules/saml/www/sp/metadata.php b/modules/saml/www/sp/metadata.php
index d8d3f7ea1dc7d88d61fc2c991d70cd3e5bf27b50..8fefb13d138a302496f757f9b9665f0ab1259722 100644
--- a/modules/saml/www/sp/metadata.php
+++ b/modules/saml/www/sp/metadata.php
@@ -1,7 +1,7 @@
 <?php
 
 if (!array_key_exists('PATH_INFO', $_SERVER)) {
-    throw new SimpleSAML_Error_BadRequest('Missing authentication source id in metadata URL');
+    throw new \SimpleSAML_Error_BadRequest('Missing authentication source id in metadata URL');
 }
 
 $config = \SimpleSAML\Configuration::getInstance();
@@ -9,13 +9,13 @@ if ($config->getBoolean('admin.protectmetadata', false)) {
     \SimpleSAML\Utils\Auth::requireAdmin();
 }
 $sourceId = substr($_SERVER['PATH_INFO'], 1);
-$source = SimpleSAML_Auth_Source::getById($sourceId);
+$source = \SimpleSAML_Auth_Source::getById($sourceId);
 if ($source === null) {
-    throw new SimpleSAML_Error_AuthSource($sourceId, 'Could not find authentication source.');
+    throw new \SimpleSAML_Error_AuthSource($sourceId, 'Could not find authentication source.');
 }
 
-if (!($source instanceof sspmod_saml_Auth_Source_SP)) {
-    throw new SimpleSAML_Error_AuthSource($sourceId,
+if (!($source instanceof \sspmod_saml_Auth_Source_SP)) {
+    throw new \SimpleSAML_Error_AuthSource($sourceId,
         'The authentication source is not a SAML Service Provider.');
 }
 
@@ -31,7 +31,7 @@ $slosvcdefault = array(
 );
 
 $slob = $spconfig->getArray('SingleLogoutServiceBinding', $slosvcdefault);
-$slol = SimpleSAML\Module::getModuleURL('saml/sp/saml2-logout.php/'.$sourceId);
+$slol = \SimpleSAML\Module::getModuleURL('saml/sp/saml2-logout.php/'.$sourceId);
 
 foreach ($slob as $binding) {
     if ($binding == \SAML2\Constants::BINDING_SOAP && !($store instanceof \SimpleSAML\Store\SQL)) {
@@ -66,35 +66,35 @@ foreach ($assertionsconsumerservices as $services) {
     switch ($services) {
         case 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST':
             $acsArray['Binding'] = \SAML2\Constants::BINDING_HTTP_POST;
-            $acsArray['Location'] = SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/'.$sourceId);
+            $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/'.$sourceId);
             if (!in_array(\SAML2\Constants::NS_SAMLP, $supported_protocols, true)) {
                 $supported_protocols[] = \SAML2\Constants::NS_SAMLP;
             }
             break;
         case 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post':
             $acsArray['Binding'] = 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post';
-            $acsArray['Location'] = SimpleSAML\Module::getModuleURL('saml/sp/saml1-acs.php/'.$sourceId);
+            $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml1-acs.php/'.$sourceId);
             if (!in_array('urn:oasis:names:tc:SAML:1.1:protocol', $supported_protocols, true)) {
                 $supported_protocols[] = 'urn:oasis:names:tc:SAML:1.1:protocol';
             }
             break;
         case 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact':
             $acsArray['Binding'] = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact';
-            $acsArray['Location'] = SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/'.$sourceId);
+            $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/'.$sourceId);
             if (!in_array(\SAML2\Constants::NS_SAMLP, $supported_protocols, true)) {
                 $supported_protocols[] = \SAML2\Constants::NS_SAMLP;
             }
             break;
         case 'urn:oasis:names:tc:SAML:1.0:profiles:artifact-01':
             $acsArray['Binding'] = 'urn:oasis:names:tc:SAML:1.0:profiles:artifact-01';
-            $acsArray['Location'] = SimpleSAML\Module::getModuleURL('saml/sp/saml1-acs.php/'.$sourceId.'/artifact');
+            $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml1-acs.php/'.$sourceId.'/artifact');
             if (!in_array('urn:oasis:names:tc:SAML:1.1:protocol', $supported_protocols, true)) {
                 $supported_protocols[] = 'urn:oasis:names:tc:SAML:1.1:protocol';
             }
             break;
         case 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser':
             $acsArray['Binding'] = 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser';
-            $acsArray['Location'] = SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/'.$sourceId);
+            $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/'.$sourceId);
             $acsArray['hoksso:ProtocolBinding'] = \SAML2\Constants::BINDING_HTTP_REDIRECT;
             if (!in_array(\SAML2\Constants::NS_SAMLP, $supported_protocols, true)) {
                 $supported_protocols[] = \SAML2\Constants::NS_SAMLP;
@@ -108,7 +108,7 @@ foreach ($assertionsconsumerservices as $services) {
 $metaArray20['AssertionConsumerService'] = $eps;
 
 $keys = array();
-$certInfo = SimpleSAML\Utils\Crypto::loadPublicKey($spconfig, false, 'new_');
+$certInfo = \SimpleSAML\Utils\Crypto::loadPublicKey($spconfig, false, 'new_');
 if ($certInfo !== null && array_key_exists('certData', $certInfo)) {
     $hasNewCert = true;
 
@@ -124,7 +124,7 @@ if ($certInfo !== null && array_key_exists('certData', $certInfo)) {
     $hasNewCert = false;
 }
 
-$certInfo = SimpleSAML\Utils\Crypto::loadPublicKey($spconfig);
+$certInfo = \SimpleSAML\Utils\Crypto::loadPublicKey($spconfig);
 if ($certInfo !== null && array_key_exists('certData', $certInfo)) {
     $certData = $certInfo['certData'];
 
@@ -257,11 +257,11 @@ if (isset($metaArray20['attributes']) && is_array($metaArray20['attributes'])) {
 }
 
 // sign the metadata if enabled
-$xml = SimpleSAML_Metadata_Signer::sign($xml, $spconfig->toArray(), 'SAML 2 SP');
+$xml = \SimpleSAML_Metadata_Signer::sign($xml, $spconfig->toArray(), 'SAML 2 SP');
 
 if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] == 'xhtml') {
 
-    $t = new SimpleSAML_XHTML_Template($config, 'metadata.php', 'admin');
+    $t = new \SimpleSAML\XHTML\Template($config, 'metadata.php', 'admin');
 
     $t->data['clipboard.js'] = true;
     $t->data['header'] = 'saml20-sp'; // TODO: Replace with headerString in 2.0
diff --git a/modules/saml/www/sp/wrong_authncontextclassref.php b/modules/saml/www/sp/wrong_authncontextclassref.php
index 490a86a40170acdaf33bd01a9b971aba52e3fc1a..9cb93bf70dbfeffbe30c113b323f9c834c9d6cce 100644
--- a/modules/saml/www/sp/wrong_authncontextclassref.php
+++ b/modules/saml/www/sp/wrong_authncontextclassref.php
@@ -1,5 +1,5 @@
 <?php
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new SimpleSAML_XHTML_Template($globalConfig, 'saml:sp/wrong_authncontextclassref.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'saml:sp/wrong_authncontextclassref.tpl.php');
 $t->show();
diff --git a/modules/sanitycheck/www/index.php b/modules/sanitycheck/www/index.php
index 55f70198fd6a3cc01c833ac7d28df72ea5a7efcb..d7302529e7d3aa9437c2e13a7949f13e2f696e4e 100644
--- a/modules/sanitycheck/www/index.php
+++ b/modules/sanitycheck/www/index.php
@@ -8,7 +8,7 @@ $hookinfo = array(
     'info' => &$info,
     'errors' => &$errors,
 );
-SimpleSAML\Module::callHooks('sanitycheck', $hookinfo);
+\SimpleSAML\Module::callHooks('sanitycheck', $hookinfo);
 
 if (isset($_REQUEST['output']) && $_REQUEST['output'] == 'text') {
 
@@ -20,7 +20,7 @@ if (isset($_REQUEST['output']) && $_REQUEST['output'] == 'text') {
     exit;
 }
 
-$t = new SimpleSAML_XHTML_Template($config, 'sanitycheck:check.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'sanitycheck:check.tpl.php');
 $t->data['pageid'] = 'sanitycheck';
 $t->data['errors'] = $errors;
 $t->data['info'] = $info;
diff --git a/modules/statistics/lib/StatDataset.php b/modules/statistics/lib/StatDataset.php
index ac56cfc7edbbf5b3dd10b41f45278ff93f6fd261..993cf3eff25eb364660046bfb16007c4e4fceaa9 100644
--- a/modules/statistics/lib/StatDataset.php
+++ b/modules/statistics/lib/StatDataset.php
@@ -5,6 +5,7 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
+
 class sspmod_statistics_StatDataset
 {
     protected $statconfig;
@@ -44,9 +45,9 @@ class sspmod_statistics_StatDataset
         $this->delimiter = '_';
         $this->max = 0;
 
-        $this->datehandlerTick = new sspmod_statistics_DateHandler($this->statconfig->getValue('offset', 0));
+        $this->datehandlerTick = new \sspmod_statistics_DateHandler($this->statconfig->getValue('offset', 0));
         if ($this->timeresconfig->getValue('customDateHandler', 'default') === 'month') {
-            $this->datehandlerFile = new sspmod_statistics_DateHandlerMonth(0);
+            $this->datehandlerFile = new \sspmod_statistics_DateHandlerMonth(0);
         } else {
             $this->datehandlerFile = $this->datehandlerTick;
         }
@@ -233,19 +234,19 @@ class sspmod_statistics_StatDataset
     public function getDelimiterPresentation()
     {
         $config = \SimpleSAML\Configuration::getInstance();
-        $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics.tpl.php');
+        $t = new \SimpleSAML\XHTML\Template($config, 'statistics:statistics.tpl.php');
 
         $availdelimiters = $this->availDelimiters();
 
         // create a delimiter presentation filter for this rule...
         if ($this->ruleconfig->hasValue('fieldPresentation')) {
             $fieldpresConfig = $this->ruleconfig->getConfigItem('fieldPresentation');
-            $classname = SimpleSAML\Module::resolveClass(
+            $classname = \SimpleSAML\Module::resolveClass(
                 $fieldpresConfig->getValue('class'),
                 'Statistics_FieldPresentation'
             );
             if (!class_exists($classname)) {
-                throw new Exception('Could not find field presentation plugin ['.$classname.']: No class found');
+                throw new \Exception('Could not find field presentation plugin ['.$classname.']: No class found');
             }
             $presentationHandler = new $classname($availdelimiters, $fieldpresConfig->getValue('config'), $t);
 
@@ -276,20 +277,20 @@ class sspmod_statistics_StatDataset
     {
         $statdir = $this->statconfig->getValue('statdir');
         $resarray = array();
-        $rules = SimpleSAML\Utils\Arrays::arrayize($this->ruleid);
+        $rules = \SimpleSAML\Utils\Arrays::arrayize($this->ruleid);
         foreach ($rules as $rule) {
             // Get file and extract results.
             $resultFileName = $statdir.'/'.$rule.'-'.$this->timeres.'-'.$this->fileslot.'.stat';
             if (!file_exists($resultFileName)) {
-                throw new Exception('Aggregated statitics file ['.$resultFileName.'] not found.');
+                throw new \Exception('Aggregated statitics file ['.$resultFileName.'] not found.');
             }
             if (!is_readable($resultFileName)) {
-                throw new Exception('Could not read statitics file ['.$resultFileName.']. Bad file permissions?');
+                throw new \Exception('Could not read statitics file ['.$resultFileName.']. Bad file permissions?');
             }
             $resultfile = file_get_contents($resultFileName);
             $newres = unserialize($resultfile);
             if (empty($newres)) {
-                throw new Exception('Aggregated statistics in file ['.$resultFileName.'] was empty.');
+                throw new \Exception('Aggregated statistics in file ['.$resultFileName.'] was empty.');
             }
             $resarray[] = $newres;
         }
diff --git a/modules/statistics/www/showstats.php b/modules/statistics/www/showstats.php
index 7dc2448ba6ed30054fada9cbd4c0a09eee3180b4..a7eeeeca0c17c78a34541531c7d068ec79dcc798 100644
--- a/modules/statistics/www/showstats.php
+++ b/modules/statistics/www/showstats.php
@@ -4,7 +4,7 @@ $config = \SimpleSAML\Configuration::getInstance();
 $statconfig = \SimpleSAML\Configuration::getConfig('module_statistics.php');
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
-sspmod_statistics_AccessCheck::checkAccess($statconfig);
+\sspmod_statistics_AccessCheck::checkAccess($statconfig);
 
 /*
  * Check input parameters
@@ -38,11 +38,11 @@ if ($preferRule2 === '_') {
 /*
  * Create statistics data.
  */
-$ruleset = new sspmod_statistics_Ruleset($statconfig);
+$ruleset = new \sspmod_statistics_Ruleset($statconfig);
 $statrule = $ruleset->getRule($preferRule);
 $rule = $statrule->getRuleID();
 
-$t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'statistics:statistics.tpl.php');
 $t->data['pageid'] = 'statistics';
 $t->data['header'] = 'stat';
 $t->data['available.rules'] = $ruleset->availableRulesNames();
@@ -66,7 +66,7 @@ try {
         }
         exit;
     }
-} catch (Exception $e) {
+} catch (\Exception $e) {
     $t->data['error'] = "No data available";
     $t->show();
     exit;
@@ -100,7 +100,7 @@ if (isset($preferRule2)) {
 
         $datasets[] = $dataset2->getPercentValues();
         $maxes[] = $dataset2->getMax();
-    } catch (Exception $e) {
+    } catch (\Exception $e) {
         $t->data['error'] = "No data available to compare";
         $t->show();
         exit;
@@ -109,7 +109,7 @@ if (isset($preferRule2)) {
 
 $dimx = $statconfig->getValue('dimension.x', 800);
 $dimy = $statconfig->getValue('dimension.y', 350);
-$grapher = new sspmod_statistics_Graph_GoogleCharts($dimx, $dimy);
+$grapher = new \sspmod_statistics_Graph_GoogleCharts($dimx, $dimy);
 
 $t->data['imgurl'] = $grapher->show($axis['axis'], $axis['axispos'], $datasets, $maxes);
 if (isset($piedata)) {
@@ -166,7 +166,7 @@ function getBaseURL($t, $type = 'get', $key = null, $value = null)
     }
 
     if ($type === 'get') {
-        return SimpleSAML\Module::getModuleURL("statistics/showstats.php").'?'.http_build_query($vars, '', '&amp;');
+        return \SimpleSAML\Module::getModuleURL("statistics/showstats.php").'?'.http_build_query($vars, '', '&amp;');
     } else {
         $text = '';
         foreach ($vars as $k => $v) {
diff --git a/modules/statistics/www/statmeta.php b/modules/statistics/www/statmeta.php
index 60c51db4cb6ad2fd6fb4ba3be6991031ac769f43..65910d8204437de3fe380f5a2d28a46a4e3bb329 100644
--- a/modules/statistics/www/statmeta.php
+++ b/modules/statistics/www/statmeta.php
@@ -3,13 +3,13 @@
 $config = \SimpleSAML\Configuration::getInstance();
 $statconfig = \SimpleSAML\Configuration::getConfig('module_statistics.php');
 
-sspmod_statistics_AccessCheck::checkAccess($statconfig);
+\sspmod_statistics_AccessCheck::checkAccess($statconfig);
 
 $aggr = new sspmod_statistics_Aggregator();
 $aggr->loadMetadata();
 $metadata = $aggr->getMetadata();
 
-$t = new SimpleSAML_XHTML_Template($config, 'statistics:statmeta.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'statistics:statmeta.tpl.php');
 
 if ($metadata !== null) {
     if (in_array('lastrun', $metadata, true)) {
diff --git a/templates/includes/attributes.php b/templates/includes/attributes.php
index 79aae3130d4579957302e6f23983a796c63a7ec4..98e6abe3147b2decc9e89918a7bede70b3ac32f5 100644
--- a/templates/includes/attributes.php
+++ b/templates/includes/attributes.php
@@ -51,7 +51,7 @@ function present_eptid(\SimpleSAML\Locale\Translate $t, \SAML2\XML\saml\NameID $
     return '<td class="attrvalue">'.present_assoc($eptid);
 }
 
-function present_attributes(SimpleSAML_XHTML_Template $t, $attributes, $nameParent)
+function present_attributes(\SimpleSAML\XHTML\Template $t, $attributes, $nameParent)
 {
     $alternate = array('odd', 'even');
     $i = 0;
@@ -100,11 +100,11 @@ function present_attributes(SimpleSAML_XHTML_Template $t, $attributes, $namePare
                         '" /></td></tr>';
                 } elseif (is_a($value[0], 'DOMNodeList')) {
                     // try to see if we have a NameID here
-                    /** @var DOMNodeList $value [0] */
+                    /** @var \DOMNodeList $value [0] */
                     $n = $value[0]->length;
                     for ($idx = 0; $idx < $n; $idx++) {
                         $elem = $value[0]->item($idx);
-                        /* @var DOMElement $elem */
+                        /* @var \DOMElement $elem */
                         if (!($elem->localName === 'NameID' && $elem->namespaceURI === \SAML2\Constants::NS_SAML)) {
                             continue;
                         }
diff --git a/www/admin/hostnames.php b/www/admin/hostnames.php
index a007aa7933d084b4e5b711711060398e1cb78efe..3b24bf53124ed099fa8acaed66abc0aa78ed9bd9 100644
--- a/www/admin/hostnames.php
+++ b/www/admin/hostnames.php
@@ -7,7 +7,7 @@ $config = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
 // Check if valid local session exists..
-SimpleSAML\Utils\Auth::requireAdmin();
+\SimpleSAML\Utils\Auth::requireAdmin();
 
 $attributes = array();
 
@@ -25,7 +25,7 @@ $attributes['getSelfHostWithPath()'] = array(\SimpleSAML\Utils\HTTP::getSelfHost
 $attributes['getFirstPathElement()'] = array(\SimpleSAML\Utils\HTTP::getFirstPathElement());
 $attributes['selfURL()'] = array(\SimpleSAML\Utils\HTTP::getSelfURL());
 
-$template = new SimpleSAML_XHTML_Template($config, 'hostnames.php');
+$template = new \SimpleSAML\XHTML\Template($config, 'hostnames.php');
 
 $template->data['remaining']  = $session->getAuthData('admin', 'Expire') - time();
 $template->data['attributes'] = $attributes;
diff --git a/www/admin/index.php b/www/admin/index.php
index 8dde15c9e8e72d692fa7ced1a5844fbea7acd527..28bec413bc6c1e4bb85438eca84abd68b9ad4054 100644
--- a/www/admin/index.php
+++ b/www/admin/index.php
@@ -7,7 +7,7 @@ $config = \SimpleSAML\Configuration::getInstance();
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
 // Check if valid local session exists..
-SimpleSAML\Utils\Auth::requireAdmin();
+\SimpleSAML\Utils\Auth::requireAdmin();
 
 $adminpages = array(
     'hostnames.php' => 'Diagnostics on hostname, port and protocol',
@@ -16,7 +16,7 @@ $adminpages = array(
     'sandbox.php' => 'Sandbox for testing changes to layout and css',
 );
 
-$template = new SimpleSAML_XHTML_Template($config, 'index.php');
+$template = new \SimpleSAML\XHTML\Template($config, 'index.php');
 
 $template->data['pagetitle'] = 'Admin';
 $template->data['adminpages'] = $adminpages;
diff --git a/www/admin/metadata-converter.php b/www/admin/metadata-converter.php
index 9a20e0046c9d64d8592c7f5b740278ad1bab269c..7fba906daf702f03af308af7488ff6a139186c24 100644
--- a/www/admin/metadata-converter.php
+++ b/www/admin/metadata-converter.php
@@ -3,7 +3,7 @@
 require_once('../_include.php');
 
 // make sure that the user has admin access rights
-SimpleSAML\Utils\Auth::requireAdmin();
+\SimpleSAML\Utils\Auth::requireAdmin();
 
 $config = \SimpleSAML\Configuration::getInstance();
 
@@ -15,7 +15,7 @@ if (!empty($_FILES['xmlfile']['tmp_name'])) {
 
 if (!empty($xmldata)) {
     \SimpleSAML\Utils\XML::checkSAMLMessage($xmldata, 'saml-meta');
-    $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($xmldata);
+    $entities = \SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($xmldata);
 
     // get all metadata for the entities
     foreach ($entities as &$entity) {
@@ -28,7 +28,7 @@ if (!empty($xmldata)) {
     }
 
     // transpose from $entities[entityid][type] to $output[type][entityid]
-    $output = SimpleSAML\Utils\Arrays::transpose($entities);
+    $output = \SimpleSAML\Utils\Arrays::transpose($entities);
 
     // merge all metadata of each type to a single string which should be added to the corresponding file
     foreach ($output as $type => &$entities) {
@@ -52,7 +52,7 @@ if (!empty($xmldata)) {
     $output = array();
 }
 
-$template = new SimpleSAML_XHTML_Template($config, 'metadata-converter.php', 'admin');
+$template = new \SimpleSAML\XHTML\Template($config, 'metadata-converter.php', 'admin');
 $template->data['clipboard.js'] = true;
 $template->data['xmldata'] = $xmldata;
 $template->data['output'] = $output;
diff --git a/www/admin/sandbox.php b/www/admin/sandbox.php
index 2f000536ba84aab5c465812650848cb089d771fc..e15d02fd7802f70f2da17506e7cc4d02e2723389 100644
--- a/www/admin/sandbox.php
+++ b/www/admin/sandbox.php
@@ -9,7 +9,7 @@ $session = \SimpleSAML\Session::getSessionFromRequest();
 // Check if valid local session exists..
 //SimpleSAML\Utils\Auth::requireAdmin();
 
-$template = new SimpleSAML_XHTML_Template($config, 'sandbox.php');
+$template = new \SimpleSAML\XHTML\Template($config, 'sandbox.php');
 
 $template->data['pagetitle'] = 'Sandbox';
 $template->data['sometext'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur.';
diff --git a/www/errorreport.php b/www/errorreport.php
index c03eb8d1e93c30871b2bef3d48a4d1ac0702ddbd..f04eb9eacbd4307a581a693a9f1ad883eaaf1ba4 100644
--- a/www/errorreport.php
+++ b/www/errorreport.php
@@ -8,7 +8,7 @@ $config = \SimpleSAML\Configuration::getInstance();
 if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
     // the message has been sent. Show error report page
 
-    $t = new SimpleSAML_XHTML_Template($config, 'errorreport.php', 'errors');
+    $t = new \SimpleSAML\XHTML\Template($config, 'errorreport.php', 'errors');
     $t->show();
     exit;
 }
@@ -21,8 +21,8 @@ $data = null;
 try {
     $session = \SimpleSAML\Session::getSessionFromRequest();
     $data = $session->getData('core:errorreport', $reportId);
-} catch (Exception $e) {
-    SimpleSAML\Logger::error('Error loading error report data: '.var_export($e->getMessage(), true));
+} catch (\Exception $e) {
+    \SimpleSAML\Logger::error('Error loading error report data: '.var_export($e->getMessage(), true));
 }
 
 if ($data === null) {
@@ -121,7 +121,7 @@ if ($from === 'no-reply@example.org' && $replyto !== null) {
 // send the email
 $toAddress = $config->getString('technicalcontact_email', 'na@example.org');
 if ($config->getBoolean('errorreporting', true) && $toAddress !== 'na@example.org') {
-    $email = new SimpleSAML_XHTML_EMail($toAddress, 'SimpleSAMLphp error report', $from);
+    $email = new \SimpleSAML\XHTML\EMail($toAddress, 'SimpleSAMLphp error report', $from);
     $email->setBody($message);
     $email->send();
     SimpleSAML\Logger::error('Report with id '.$reportId.' sent to <'.$toAddress.'>.');
diff --git a/www/logout.php b/www/logout.php
index 97d4a7fec7e4a768b330ffcb75d64de90bc419ce..97c7d2b41b2c768512fc4703fb4837e70eb50969 100644
--- a/www/logout.php
+++ b/www/logout.php
@@ -16,7 +16,7 @@ if (array_key_exists('link_text', $_REQUEST)) {
     $text = '{logout:default_link_text}';
 }
 
-$t = new SimpleSAML_XHTML_Template($config, 'logout.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'logout.php');
 $t->data['link'] = $link;
 $t->data['text'] = $text;
 $t->show();
diff --git a/www/saml2/idp/metadata.php b/www/saml2/idp/metadata.php
index d68e8473a77557a4e69fe9167c20b439b7808c46..5b2c3d3be89b1c3a3143491e833f061c37d7944d 100644
--- a/www/saml2/idp/metadata.php
+++ b/www/saml2/idp/metadata.php
@@ -8,9 +8,9 @@ use SimpleSAML\Utils\Crypto as Crypto;
 use SimpleSAML\Utils\HTTP as HTTP;
 use SimpleSAML\Utils\Config\Metadata as Metadata;
 
-// load SimpleSAMLphp, configuration and metadata
+// load SimpleSAMLphp configuration and metadata
 $config = \SimpleSAML\Configuration::getInstance();
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
 if (!$config->getBoolean('enable.saml20-idp', false)) {
     throw new SimpleSAML_Error_Error('NOACCESS');
@@ -148,7 +148,7 @@ try {
         );
 
         if (!$idpmeta->hasValue('OrganizationURL')) {
-            throw new SimpleSAML_Error_Exception('If OrganizationName is set, OrganizationURL must also be set.');
+            throw new \SimpleSAML_Error_Exception('If OrganizationName is set, OrganizationURL must also be set.');
         }
         $metaArray['OrganizationURL'] = $idpmeta->getLocalizedString('OrganizationURL');
     }
@@ -210,12 +210,12 @@ try {
     $metaflat = '$metadata['.var_export($idpentityid, true).'] = '.var_export($metaArray, true).';';
 
     // sign the metadata if enabled
-    $metaxml = SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');
+    $metaxml = \SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');
 
     if (array_key_exists('output', $_GET) && $_GET['output'] == 'xhtml') {
         $defaultidp = $config->getString('default-saml20-idp', null);
 
-        $t = new SimpleSAML_XHTML_Template($config, 'metadata.php', 'admin');
+        $t = new \SimpleSAML\XHTML\Template($config, 'metadata.php', 'admin');
 
         $t->data['clipboard.js'] = true;
         $t->data['available_certs'] = $availableCerts;
@@ -234,5 +234,5 @@ try {
         exit(0);
     }
 } catch (Exception $exception) {
-    throw new SimpleSAML_Error_Error('METADATA', $exception);
+    throw new \SimpleSAML_Error_Error('METADATA', $exception);
 }
diff --git a/www/shib13/idp/metadata.php b/www/shib13/idp/metadata.php
index d580e2d40e07f9eade592bf220e692f13a9c1d47..9b94da9edd37ba9049aa1fef55fb9f434b24249d 100644
--- a/www/shib13/idp/metadata.php
+++ b/www/shib13/idp/metadata.php
@@ -4,15 +4,15 @@ require_once('../../_include.php');
 
 // load configuration and metadata
 $config = \SimpleSAML\Configuration::getInstance();
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
 if (!$config->getBoolean('enable.shib13-idp', false)) {
-    throw new SimpleSAML_Error_Error('NOACCESS');
+    throw new \SimpleSAML_Error_Error('NOACCESS');
 }
 
 // check if valid local session exists
 if ($config->getBoolean('admin.protectmetadata', false)) {
-    SimpleSAML\Utils\Auth::requireAdmin();
+    \SimpleSAML\Utils\Auth::requireAdmin();
 }
 
 try {
@@ -22,7 +22,7 @@ try {
     $idpmeta = $metadata->getMetaDataConfig($idpentityid, 'shib13-idp-hosted');
 
     $keys = array();
-    $certInfo = SimpleSAML\Utils\Crypto::loadPublicKey($idpmeta, false, 'new_');
+    $certInfo = \SimpleSAML\Utils\Crypto::loadPublicKey($idpmeta, false, 'new_');
     if ($certInfo !== null) {
         $keys[] = array(
             'type'            => 'X509Certificate',
@@ -32,7 +32,7 @@ try {
         );
     }
 
-    $certInfo = SimpleSAML\Utils\Crypto::loadPublicKey($idpmeta, true);
+    $certInfo = \SimpleSAML\Utils\Crypto::loadPublicKey($idpmeta, true);
     $keys[] = array(
         'type'            => 'X509Certificate',
         'signing'         => true,
@@ -62,12 +62,11 @@ try {
         );
 
         if (!$idpmeta->hasValue('OrganizationURL')) {
-            throw new SimpleSAML_Error_Exception('If OrganizationName is set, OrganizationURL must also be set.');
+            throw new \SimpleSAML_Error_Exception('If OrganizationName is set, OrganizationURL must also be set.');
         }
         $metaArray['OrganizationURL'] = $idpmeta->getLocalizedString('OrganizationURL');
     }
 
-
     $metaflat = '$metadata['.var_export($idpentityid, true).'] = '.var_export($metaArray, true).';';
 
     $metaBuilder = new \SimpleSAML\Metadata\SAMLBuilder($idpentityid);
@@ -81,13 +80,12 @@ try {
     $metaxml = $metaBuilder->getEntityDescriptorText();
 
     // sign the metadata if enabled
-    $metaxml = SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'Shib 1.3 IdP');
-
+    $metaxml = \SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'Shib 1.3 IdP');
 
     if (array_key_exists('output', $_GET) && $_GET['output'] == 'xhtml') {
         $defaultidp = $config->getString('default-shib13-idp', null);
 
-        $t = new SimpleSAML_XHTML_Template($config, 'metadata.php', 'admin');
+        $t = new \SimpleSAML\XHTML\Template($config, 'metadata.php', 'admin');
 
         $t->data['clipboard.js'] = true;
         $t->data['header'] = 'shib13-idp'; // TODO: Replace with headerString in 2.0
@@ -107,6 +105,6 @@ try {
         echo $metaxml;
         exit(0);
     }
-} catch (Exception $exception) {
-    throw new SimpleSAML_Error_Error('METADATA', $exception);
+} catch (\Exception $exception) {
+    throw new \SimpleSAML_Error_Error('METADATA', $exception);
 }