public function get_module_instance(event_interface $event) {
        if (!$event->get_course_module()) {
            return null;
        }

        if (is_null($this->moduleinstances)) {
            $this->load_module_instances();
        }

        $id = $event->get_course_module()->get('instance');
        $name = $event->get_course_module()->get('modname');

        if (isset($this->moduleinstances[$name])) {
            if (isset($this->moduleinstances[$name][$id])) {
                return $this->moduleinstances[$name][$id];
            }
        }

        return null;
    }