public static function closeOutputBuffers($targetLevel, $flush) {
		$status = ob_get_status(true);
		$level = count($status);

		while ($level-- > $targetLevel
			   && (!empty($status[$level]['del'])
				   || (isset($status[$level]['flags'])
					   && ($status[$level]['flags'] & PHP_OUTPUT_HANDLER_REMOVABLE)
					   && ($status[$level]['flags'] & ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE))
				   )
			   )
		) {
			if ($flush) {
				ob_end_flush();
			} else {
				ob_end_clean();
			}
		}
	}