protected function loadModel($modelName, $directories): ModelAbstract
    {
        if (empty($directories))
        {
            throw new ModelException("Could not load model. No directories provided", 1);
        }

        // Now figure out the className and subdir
        $class = trim($modelName, '/');
        if (($last_slash = strrpos($class, '/')) !== FALSE)
        {
            // Extract the path
            $subdir = substr($class, 0, ++$last_slash);

            // Get the filename from the path
            $class = substr($class, $last_slash);
        }
        else
        {
            $subdir = '';
        }

        $class = ucfirst($class);

        // Search for the model file
        foreach ($directories as $directory) {

            // Determine the file
            $file = $directory . DS . $subdir . "model." . strtolower($class) . '.php';
            $className = '\Application\Model\\'.$class;

            // If the class already exists, return a new instance directly
            if (class_exists($className, false))
            {
                return new $className();
            }

            // If it doesn't, try and load the file
            if (file_exists($file))
            {
                include_once($file);
                return new $className();
            }
        }

        // Maybe it's in a subdirectory with the same name as the class
        if ($subdir === '')
        {
            return $this->loadModel($class."/".$class, $directories);
        }

        throw new ModelException("Could not load model. Model was not found", 1);
    }