protected function realLoadModule(
        $module,
        $chan,
        $flags,
        &$plainModules,
        &$channelModules
    ) {
        if ($chan !== null) {
            if (isset($channelModules[$chan][$module])) {
                return $channelModules[$chan][$module];
            }
        } elseif (isset($plainModules[$module])) {
            return $plainModules[$module];
        }

        if (!class_exists($module, true)) {
            throw new \Erebot\InvalidValueException("No such class '$module'");
        }

        if (!is_subclass_of($module, '\\Erebot\\Module\\Base')) {
            throw new \Erebot\InvalidValueException(
                "Invalid module! Not a subclass of \\Erebot\\Module\\Base."
            );
        }

        $reflector = new \ReflectionClass($module);
        $instance = new $module($chan);
        if ($chan === null) {
            $plainModules[$module] = $instance;
        } else {
            $channelModules[$chan][$module] = $instance;
        }

        $instance->reloadModule($this, $flags);
        $logger = \Plop\Plop::getInstance();
        $logger->info(
            $this->bot->gettext("Successfully loaded module '%(module)s' [%(source)s]"),
            array(
                'module' => $module,
                'source' => (substr($reflector->getFileName(), 0, 7) == 'phar://')
                            ? $this->bot->gettext('PHP archive')
                            : $this->bot->gettext('regular file'),
            )
        );
        return $instance;
    }