private function handle($routes, $fireAfterRoutingCallback = false)
    {
        // Counter to keep track of the number of routes we've handled
        $handledRequest = 0;

        $i = 0;
        // Loop all routes
        foreach ($routes as $route) {
            if ($matches = $this->isPatternMatches($route['pattern'], true)) {
                if ($this->middleware) {
                    $this->handleMiddleware();
                }

                // Extract the matched URL (and only the parameters)
                $params = $this->extractParams($matches);
                array_unshift($params, $this);

                // call the handling function with the URL
                $this->handledRoute = call_user_func_array($route['fn'], $params);
                $this->container->set('response', $this->handledRoute);

                $handledRequest++;

                // If we need to quit, then quit
                if ($fireAfterRoutingCallback) {
                    // If a route was handled, perform the finish callback (if any)
                    $this->handle($this->afterRouter);
                }
            }
            $i++;
        }

        // Return the number of routes handled
        return $handledRequest;
    }