diff --git a/course/deletesection.php b/course/deletesection.php
index e112b38..3c30222 100644
--- a/course/deletesection.php
+++ b/course/deletesection.php
@@ -14,17 +14,19 @@
         error("Course section is incorrect");
     }
 
-    if (! $course = get_record("course", "id", $section->course)) {
-        error("Could not find the course!");
-    }
-
     if ( $section->section == 0) {
         error("Course section 0 (main) could not be deleted");
     }
 
+    if (! $course = get_record("course", "id", $section->course)) {
+        error("Could not find the course!");
+    }
+
     require_login($course->id);
 
-    require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
+    $context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+    require_capability('moodle/course:manageactivities', $context);
 
     if (! $delete) {
         $delete_section = get_string("deletesection");
@@ -56,7 +58,7 @@
     if (!empty($section->sequence) ) {
         $modids = split(',', $section->sequence);
         foreach($modids AS $modid) {
-            deletesection_delete_module($modid);
+            deletesection_delete_module($modid, $course);
         }
     }
 
diff --git a/course/deletesectionlib.php b/course/deletesectionlib.php
index 5e0561f..5bae743 100644
--- a/course/deletesectionlib.php
+++ b/course/deletesectionlib.php
@@ -7,21 +7,23 @@ function deletesection_delete_module($modid, $course) {
         error("This course module doesn't exist");
     }
 
+    require_login($cm->course); // needed to setup proper $COURSE
+
     if (! $module = get_record("modules", "id", $cm->module)) {
         error("This module doesn't exist");
     }
 
     if (! $instance = get_record($module->name, "id", $cm->instance)) {
-        // Delete this module from the course right away
-        if (! delete_mod_from_section($cm->id, $cm->section)) {
-            notify("Could not delete the $module->name from that section");
-        }
-        if (! delete_course_module($cm->id)) {
-            notify("Could not delete the $module->name (coursemodule)");
-        }
-        print_error("The required instance of this module didn't exist.  Module deleted.",
+        error("The required instance of this module didn't exist.  Module deleted.",
                     "$CFG->wwwroot/course/view.php?id=$course->id");
     }
+    // Delete this module from the course right away
+    if (! delete_mod_from_section($cm->id, $cm->section)) {
+        error("Could not delete the $module->name from that section");
+    }
+    if (! delete_course_module($cm->id)) {
+        error("Could not delete the $module->name (coursemodule)");
+    }
     return true;
 }
 
