public static function stop($name)
    {
        if (!self::isEnabled()) {
            return;
        }

        $currentName = end(self::$stack);
        if ($currentName != $name) {
            if (Mage::getStoreConfigFlag('dev/debug/logInvalidNesting')) {
                Mage::log('[INVALID NESTING!] Found: ' . $name . " | Expecting: $currentName");
            }

            if (in_array($name, self::$stack)) {
                // trying to stop something that has been started before,
                // but there are other unstopped stack items
                // -> auto-stop them
                while (($latestStackItem = end(self::$stack)) != $name) {
                    if (Mage::getStoreConfigFlag('dev/debug/logInvalidNesting')) {
                        Mage::log('Auto-stopping timer "' . $latestStackItem . '" because of incorrect nesting');
                    }
                    self::stop($latestStackItem);
                }
            } else {
                // trying to stop something that hasn't been started before -> just ignore
                return;
            }

            // We shouldn't add another name to the stack if we've already crawled up to the current one...
            // $name = '[INVALID NESTING!] ' . $name;
            // self::start($name);
            // return;
            // throw new Exception(sprintf("Invalid nesting! Expected: '%s', was: '%s'", $currentName, $name));
        }

        $currentPointer = end(self::$currentPointerStack);

        self::$stackLog[$currentPointer]['time_end'] = microtime(true);
        self::$stackLog[$currentPointer]['realmem_end'] = memory_get_usage(true);
        // self::$stackLog[$currentPointer]['emalloc_end'] = memory_get_usage(false);

        // TODO: introduce configurable threshold
        if (self::$_logCallStack !== false) {
            self::$stackLog[$currentPointer]['callstack'] = Varien_Debug::backtrace(true, false);
        }

        self::$stackLevel--;
        array_pop(self::$stack);
        array_pop(self::$currentPointerStack);
    }