fix blank page
diff --git a/index.php b/index.php
index 340a22e..9b9b31a 100755
--- a/index.php
+++ b/index.php
@@ -5,28 +5,33 @@
 include_once 'utils.php';
 
 if (!$DEBUG)    error_reporting(0);
+else error_reporting(1);
 session_start();
 
-$INCLUDE_STRINGS_PATH = "templates_".$LANG_CC;
-if (isset($LANG_CC) && !empty($LANG_CC)) $TEMPLATE = $INCLUDE_STRINGS_PATH;
-else $TEMPLATE = "templates";
-
-include_once $TEMPLATE.'/strings.php';
-
-if(!file_exists(stream_resolve_include_path($INCLUDE_STRINGS_PATH.'/strings.php'))){
-    echo format($RUNTIME_ERROR->template_not_found, ["template"=>$INCLUDE_STRINGS_PATH, "langcc"=>$LANG_CC]);
-}
-
-
 use Gregwar\Captcha\PhraseBuilder;
 
+$URI = array_slice(explode("/", explode('?', $_SERVER['REQUEST_URI'], 2)[0]), -1)[0];
+if (strlen($URI) == 2){
+    $GLOBALS["cc"] = $URI;
+    $_SESSION["cc"] = $URI;
+}
+
+if (isset($_GET["lang"])){
+    $GLOBALS["cc"] = $_GET["lang"];
+    $_SESSION["cc"] = $_GET["lang"];
+}
+
+$TEMPLATE = template_path();
+
+
 
 function register_page($error=false){
+    $TEMPLATE = template_path();
     include 'config.php';
     if ($error)
-        include $TEMPLATE.'/error.htm';
+        include $TEMPLATE.'error.htm';
     $_SESSION["captcha_token"] = generateRandomString(12);
-    include $TEMPLATE."/register.htm";
+    include $TEMPLATE."register.htm";
     echo '
     <script>
         const reload_captcha = async (e) => {
@@ -54,9 +59,10 @@
 
 
 function verify_request($user){
+    $TEMPLATE = template_path();
     unset($_SESSION['captcha_token']);
-    include_once 'validators.php';
-    include_once $TEMPLATE.'/strings.php';
+    include 'validators.php';
+    include $TEMPLATE.'strings.php';
     $password = $_POST["password"];
     $error = "";
 
@@ -77,10 +83,7 @@
 
 function approve_request($user){
     include "mail.php";
-    $token = "";
-    do {
-        $token = generateRandomString();
-    } while (redis_get($token));
+    $token = generateRandomString();
     redis_set($token, $user, $MAIL_CONFIRMATION_AWAIT_DELAY);
     $pending = redis_get("pending");
     if ($pending){
@@ -104,12 +107,13 @@
     $_SESSION['resend'] = generateRandomString(12);
     $_SESSION['token'] = $token;
     $_SESSION['email'] = $user->email;
+    $TEMPLATE = template_path();
     include $TEMPLATE."confirm_your_email.htm";
 }
 
 
 // PAGE
-include $TEMPLATE."/header.htm";
+include $TEMPLATE."header.htm";
 
 if ($_SERVER["REQUEST_METHOD"] == "POST") {
     include 'ldap.php';
@@ -118,7 +122,7 @@
             case "register":
                 $user = new User($_POST["username"], $_POST["name"], $_POST["last_name"], $_POST["email"], $_POST["password"]); 
                 if (redis_inc_ipdata(getClientIP(), "register", true) > $HOURLY_REGISTRATIONS){
-                    include $TEMPLATE."/registration_limit.htm";
+                    include $TEMPLATE."registration_limit.htm";
                 }else{
                     $error = verify_request($user);
                     if ($error)
@@ -155,21 +159,21 @@
                         }
                         redis_inc_ipdata(getClientIP(), "register");
                         echo $STRINGS->email_confirmation;
-                        include $TEMPLATE."/mail_confirmed.htm";
+                        include $TEMPLATE."mail_confirmed.htm";
                     }else{
                         echo $STRINGS->email_confirmation;
-                        include $TEMPLATE."/registration_error.htm";
+                        include $TEMPLATE."registration_error.htm";
                     }
                     redis_delete($token);
                 }else{
-                    include $TEMPLATE."/token_expired.htm";
+                    include $TEMPLATE."token_expired.htm";
                 }
             }
             break;
         case "resend":
             if (isset($_GET['token']) && isset($_SESSION['resend']) && $_GET['token'] == $_SESSION['resend']){
                 include "mail.php";
-                include $TEMPLATE."/resend_mail.htm";
+                include $TEMPLATE."resend_mail.htm";
                 $token = $_SESSION['token'];
                 $url = $BASE_URL."?type=confirmation&token=".$token;
                 $smtp = $FALLBACK_SMTP;
@@ -196,5 +200,4 @@
     register_page();
 }
 
-include $TEMPLATE."/bottom.htm";
-?>
+include $TEMPLATE."bottom.htm";
diff --git a/templates/strings.php b/templates/strings.php
index 91e1d86..6133ccc 100644
--- a/templates/strings.php
+++ b/templates/strings.php
@@ -1,6 +1,7 @@
 <?php
 $RUNTIME_ERROR = (object)[
-        "template_not_found" => "Either you did not create the folder {{template}} or strings.php is missing on it. Maybe you have set {{langcc}} wrong on config.php?",
+        "not_found" => "<center><h2>This page does not exist!</h2></center>",
+        "template_not_found" => "Either you did not create the folder '{{template}}' or strings.php is missing on it. Maybe you have set LANG_CC: '{{langcc}}' wrong on config.php?",
         "user_trying_invalid_get" => "INVALID REQUEST. THERE IS NOTHING HERE FOR YOU",
 ];
 
diff --git a/utils.php b/utils.php
index 6086153..ea2e7e5 100644
--- a/utils.php
+++ b/utils.php
@@ -28,3 +28,30 @@
     }
     return $string;
 }
+
+function template_path(string $lang_cc = null){
+    include "config.php";
+    if (isset($_SESSION["cc"]))
+        $lang_cc = $GLOBALS["cc"];
+    if (isset($GLOBALS["cc"]))
+        $lang_cc = $GLOBALS["cc"];
+    if ($lang_cc)
+        $INCLUDE_STRINGS_PATH = "templates_".$lang_cc;
+    else
+        $INCLUDE_STRINGS_PATH = "templates";
+
+    if (isset($lang_cc) && !empty($lang_cc)) $TEMPLATE = $INCLUDE_STRINGS_PATH."/";
+    else $TEMPLATE = "templates/";
+
+    include $TEMPLATE.'strings.php';
+
+    if(!isset($RUNTIME_ERROR)){
+        include_once 'templates/strings.php';
+        echo $RUNTIME_ERROR->not_found;
+        echo "<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";
+        echo format($RUNTIME_ERROR->template_not_found, ["template"=>$INCLUDE_STRINGS_PATH, "langcc"=>$LANG_CC]);
+        die();
+    }
+
+    return $TEMPLATE;
+}
diff --git a/validators.php b/validators.php
index 4bcbe42..821c391 100644
--- a/validators.php
+++ b/validators.php
@@ -1,18 +1,16 @@
 <?php
-include_once'ldap.php';
-include_once'redis.php';
-include_once'config.php';
-include_once'utils.php';
+include_once 'ldap.php';
+include_once 'redis.php';
+include_once 'config.php';
+include_once 'utils.php';
 
-$INCLUDE_STRINGS_PATH = "templates_".$LANG_CC;
-if (isset($LANG_CC) && !empty($LANG_CC)) $TEMPLATE = $INCLUDE_STRINGS_PATH;
-else $TEMPLATE = "templates";
-
+$TEMPLATE = template_path();
 
 function validate_username(string $username)
 {
-        include_once'config.php';
-        include_once$TEMPLATE.'/strings.php';
+        global $TEMPLATE;
+        include 'config.php';
+        include $TEMPLATE . 'strings.php';
         $error = "";
         if (ldap_user_count($username)) {
                 $error = $error . $USERNAME_VALIDATION_ERROR->registered;
@@ -23,7 +21,10 @@
                 unset($_POST["username"]);
         }
         if (strlen($username) > $VAL_USER->max_username) {
+                echo $VAL_USER->max_username;
+                echo $USERNAME_VALIDATION_ERROR->smaller_than;
                 $error = $error . format($USERNAME_VALIDATION_ERROR->smaller_than, ["num" => $VAL_USER->max_username + 1]);
+                echo $error;
                 unset($_POST["username"]);
         }
         if (strlen($username) < $VAL_USER->min_username) {
@@ -38,9 +39,9 @@
                 $error = $error . $USERNAME_VALIDATION_ERROR->no_number_begining;
                 unset($_POST["username"]);
         }
-        include_once"blacklists/usernames.php";
+        include "blacklists/usernames.php";
         if (in_array($username, $USERNAME_BLACKLIST)) {
-                $error = $error . $USERNAME_VALIDATION_ERROR->blacklisted; 
+                $error = $error . $USERNAME_VALIDATION_ERROR->blacklisted;
                 unset($_POST["username"]);
         }
         return $error;
@@ -48,8 +49,9 @@
 
 function validate_name(string $name, object $ERRORS)
 {
-        include_once "config.php";
-        include_once$TEMPLATE.'/strings.php';
+        global $TEMPLATE;
+        include "config.php";
+        include $TEMPLATE . 'strings.php';
         $error = "";
         if (preg_match("/\s/", $name)) {
                 $error = $error . $ERRORS->no_whitespaces;
@@ -72,12 +74,13 @@
 
 function validate_email(string $email)
 {
-        include_once "config.php";
-        include_once$TEMPLATE.'/strings.php';
+        global $TEMPLATE;
+        include "config.php";
+        include $TEMPLATE . 'strings.php';
         $error = "";
 
         if (ldap_mail_count($email)) {
-                $error = $error . format($EMAIL_VALIDATION_ERROR->registered, ["link" => $BASE_URL."?type=recover"]);
+                $error = $error . format($EMAIL_VALIDATION_ERROR->registered, ["link" => $BASE_URL . "?type=recover"]);
                 unset($_POST["email"]);
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
@@ -101,8 +104,9 @@
 
 function validate_password(string $password)
 {
-        include_once "config.php";
-        include_once$TEMPLATE.'/strings.php';
+        global $TEMPLATE;
+        include "config.php";
+        include $TEMPLATE . 'strings.php';
         $error = "";
         if ($_POST["password"] != $_POST["password_confirm"]) {;
                 $error = $error . $PASSWORD_VALIDATION_ERROR->no_match;
@@ -118,7 +122,7 @@
                 unset($_POST["password"]);
                 unset($_POST["password_confirm"]);
         }
-        include_once"blacklists/password.php";
+        include "blacklists/password.php";
         if (in_array($password, $PASSWORD_BLACKLIST)) {
                 $error = $error . $PASSWORD_VALIDATION_ERROR->blacklisted;
                 unset($_POST["password"]);