diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php
index f9926045498e029f8427c584ab13f412e8d9e6f0..749f8891f8163eca5496358eebdcd8115e5cd102 100644
--- a/apps/gallery/templates/index.php
+++ b/apps/gallery/templates/index.php
@@ -101,10 +101,8 @@ for($i = 0; $i < count($images); $i++) {
 
 $dir_arr = explode('/', $previous_element);
 
-if (count($images)>1) {
-  if (count($dir_arr)==0) {
-    $tl->addTile(new \OC\Pictures\TileSingle($previous_element));
-  } else if (count($dir_arr) && $ts->getCount() == 0){
+if (count($images)>1 && count($dir_arr) > 1) {
+  if (count($dir_arr) && $ts->getCount() == 0){
       $ts = new \OC\Pictures\TileStack(array($root.$previous_element), $dir_arr[0]);
   } else {
     $arr[] = $previous_element;