diff --git a/lib/dunemodules.lib b/lib/dunemodules.lib
index 071b172f1103f1f74e2db611ad324612b93904ce..95eddc8906426c7f67961fba4fb5fd1372883c50 100644
--- a/lib/dunemodules.lib
+++ b/lib/dunemodules.lib
@@ -263,6 +263,7 @@ sort_modules() {
   export SORTEDMODULES_MAIN
   # clean up temporary variables
   for m in $MODULES; do
+    export MODE_$m=""
     export SORT_DONE_$m=""
     export SORT_DEPS_DONE_$m=""
     export SORT_SUGS_DONE_$m=""
@@ -394,7 +395,9 @@ _sort_module() {
     # resolve suggestions
     _check_deps $module SUGS SUGS
     # remember mode of the module
-    export MODE_$module=$mode
+    if eval test "x\$MODE_$module" = xSUGS -o  "x\$MODE_$module" = x; then
+      export MODE_$module=$mode
+    fi
     # topological list of the module and its dependencies/suggestions
     if eval test "x\$SORT_DONE_$module" != "xyes"; then
       export SORT_DONE_$module=yes