diff --git a/admin/index.php b/admin/index.php
index <HASH>..<HASH> 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -40,7 +40,9 @@ if (version_compare(phpversion(), '5.2.0') < 0) {
 
 // try to flush everything all the time
 @ob_implicit_flush(true);
-while(@ob_end_clean()); // ob_end_flush prevents sending of headers
+while(ob_get_level()) {
+    ob_end_clean(); // ob_end_flush prevents sending of headers
+}
 
 require('../config.php');
 require_once($CFG->libdir.'/adminlib.php');    // various admin-only functions
diff --git a/lib/weblib.php b/lib/weblib.php
index <HASH>..<HASH> 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -2522,11 +2522,11 @@ function redirect($url, $message='', $delay=-1) {
 
     if (function_exists('error_get_last')) {
         $lasterror = error_get_last();
+        //NOTE: problem here is that this contains error even if error hidden with @do();
     }
     $debugdisableredirect = defined('DEBUGGING_PRINTED') ||
             (!empty($CFG->debugdisplay) && !empty($lasterror) && ($lasterror['type'] & DEBUG_DEVELOPER));
 
-    $usingmsg = false;
     if (!empty($message)) {
         if ($delay === -1 || !is_numeric($delay)) {
             $delay = 3;
MDL-<I> fixed hidden error preventing proper redirects during install, yay!