diff --git a/beat/web/backend/utils.py b/beat/web/backend/utils.py
index beacf960cf5a8099c7931592592d37d37afa463c..2871ca269a68ca2c1851b28127972f9e395510b8 100644
--- a/beat/web/backend/utils.py
+++ b/beat/web/backend/utils.py
@@ -89,13 +89,7 @@ def cleanup_cache(path, age_in_minutes=0, delete=False):
 
     removed_files = []
 
-    def _remove_dirs(p):
-        d = os.path.dirname(p)
-        if not os.listdir(d):
-            logger.info("[rmdir] `%s'", d)
-            os.removedirs(d)
-
-    for p, dirs, files in os.walk(path, topdown=True):
+    for p, dirs, files in os.walk(path, topdown=False):
 
         files = [f for f in files if not f.startswith('.')]
         dirs[:] = [d for d in dirs if not d.startswith('.')] #note: in-place
@@ -114,7 +108,6 @@ def cleanup_cache(path, age_in_minutes=0, delete=False):
                 if delete:
                     logger.info("[rm] `%s' (dangling)", fullpath)
                     os.remove(fullpath)
-                    _remove_dirs(fullpath)
                 removed_files.append(fullpath)
 
                 continue
@@ -124,7 +117,6 @@ def cleanup_cache(path, age_in_minutes=0, delete=False):
                 if delete:
                     logger.info("[rm] `%s'", fullpath)
                     os.remove(fullpath)
-                    _remove_dirs(fullpath)
                 removed_files.append(fullpath)
             else:
                 logger.debug("[skip] `%s' (%f >= %f)", fullpath,
@@ -132,7 +124,8 @@ def cleanup_cache(path, age_in_minutes=0, delete=False):
 
         for d in dirs: #also remove empty directories
             fullpath = os.path.join(p, d)
-            if not os.listdir(fullpath) and delete: os.removedirs(fullpath)
+            if not os.listdir(fullpath) and delete:
+                os.rmdir(fullpath)
 
     return removed_files