diff --git a/src/sheet-style.c b/src/sheet-style.c
index 74fb01c..6b50e66 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -49,6 +49,18 @@ struct _GnmSheetStyleData {
 	GnmColor   *auto_pattern_color;
 };
 
+static gboolean debug_style_optimize;
+
+typedef struct {
+	GnmSheetSize const *ss;
+	gboolean recursion;
+} CellTileOptimize;
+
+static void
+cell_tile_optimize (CellTile **tile, int level, CellTileOptimize *data,
+		    int ccol, int crow);
+
+
 /**
  * sheet_style_unlink
  * For internal use only
@@ -559,6 +571,8 @@ sheet_style_init (Sheet *sheet)
 	int cols = gnm_sheet_get_max_cols (sheet);
 	int rows = gnm_sheet_get_max_rows (sheet);
 
+	debug_style_optimize = gnm_debug_flag ("style-optimize");
+
 	sheet_style_sanity_check ();
 
 	sheet_style_init_size (sheet, cols, rows);
@@ -881,13 +895,13 @@ cell_tile_apply (CellTile **tile, int level,
 				int i = indic.start.col;
 				for (;i <= indic.end.col ; ++i)
 					rstyle_apply ((*tile)->style_col.style + i, rs);
-				return;
+				goto try_optimize;
 			}
 			if (type != TILE_PTR_MATRIX) {
 				indic.start.row = 0;
 				indic.end.row = TILE_SIZE_ROW - 1;
 				*tile = cell_tile_matrix_set (*tile, &indic, rs);
-				return;
+				goto try_optimize;
 			}
 		}
 	} else if (full_width) {
@@ -904,13 +918,13 @@ cell_tile_apply (CellTile **tile, int level,
 				int i = indic.start.row;
 				for (;i <= indic.end.row ; ++i)
 					rstyle_apply ((*tile)->style_row.style + i, rs);
-				return;
+				goto try_optimize;
 			}
 			if (type != TILE_PTR_MATRIX) {
 				indic.start.col = 0;
 				indic.end.col = TILE_SIZE_COL - 1;
 				*tile = cell_tile_matrix_set (*tile, &indic, rs);
-				return;
+				goto try_optimize;
 			}
 		}
 	} else {
@@ -920,7 +934,7 @@ cell_tile_apply (CellTile **tile, int level,
 				  &indic.start.row, &indic.end.row) &&
 		    type != TILE_PTR_MATRIX) {
 			*tile = cell_tile_matrix_set (*tile, &indic, rs);
-			return;
+			goto try_optimize;
 		}
 	}
 
@@ -933,7 +947,6 @@ cell_tile_apply (CellTile **tile, int level,
 
 	/* drill down */
 	g_return_if_fail (type == TILE_PTR_MATRIX);
-	level--;
 	for (i = r = 0 ; r < TILE_SIZE_ROW ; ++r, i += TILE_SIZE_COL) {
 		int const cr = corner_row + h*r;
 		if (cr > apply_to->end.row)
@@ -948,13 +961,18 @@ cell_tile_apply (CellTile **tile, int level,
 			if ((cc + w) <= apply_to->start.col)
 				continue;
 
-			/* TODO : we could be smarter and merge things
-			 * if the sub tiles become uniform
-			 */
 			cell_tile_apply ((*tile)->ptr_matrix.ptr + i + c,
-					 level, cc, cr, apply_to, rs);
+					 level - 1, cc, cr, apply_to, rs);
 		}
 	}
+
+try_optimize:
+	{
+		CellTileOptimize cto;
+		cto.ss = gnm_sheet_get_size (rs->sheet);
+		cto.recursion = FALSE;
+		cell_tile_optimize (tile, level, &cto, corner_col, corner_row);
+	}
 }
 
 typedef void (*ForeachTileFunc) (GnmStyle *style,
@@ -2590,11 +2608,6 @@ sheet_style_foreach (Sheet const *sheet, GHFunc	func, gpointer user_data)
 
 /* ------------------------------------------------------------------------- */
 
-typedef struct {
-	GnmSheetSize const *ss;
-	gboolean debug;
-} CellTileOptimize;
-
 static void
 cell_tile_optimize (CellTile **tile, int level, CellTileOptimize *data,
 		    int ccol, int crow)
@@ -2684,8 +2697,9 @@ cell_tile_optimize (CellTile **tile, int level, CellTileOptimize *data,
 			for (c = 0 ; c < TILE_SIZE_COL ; ++c) {
 				int const cc = ccol + w*c;
 				CellTile const *tcr, *tc0, *t0r;
-				cell_tile_optimize ((*tile)->ptr_matrix.ptr + i + c,
-						    level - 1, data, cc, cr);
+				if (data->recursion)
+					cell_tile_optimize ((*tile)->ptr_matrix.ptr + i + c,
+							    level - 1, data, cc, cr);
 				tcr = (*tile)->ptr_matrix.ptr[i + c];
 				t0r = (*tile)->ptr_matrix.ptr[i];
 				tc0 = (*tile)->ptr_matrix.ptr[c];
@@ -2724,14 +2738,14 @@ cell_tile_optimize (CellTile **tile, int level, CellTileOptimize *data,
 				gnm_style_link (mstyle);
 			}
 		} else if (all_simple) {
-			if (data->debug)
+			if (debug_style_optimize)
 				g_printerr ("Could turn %s into a matrix\n",
 					    range_as_string (&rng));
 			return;
 		} else
 			return;
 
-		if (data->debug)
+		if (debug_style_optimize)
 			g_printerr ("Turning %s (%dx%d) from a %s into a %s\n",
 				    range_as_string (&rng),
 				    range_width (&rng), range_height (&rng),
@@ -2746,7 +2760,7 @@ cell_tile_optimize (CellTile **tile, int level, CellTileOptimize *data,
 		g_assert_not_reached ();
 	}
 
-	if (data->debug)
+	if (debug_style_optimize)
 		g_printerr ("Turning %s (%dx%d) from a %s into a %s\n",
 			    range_as_string (&rng),
 			    range_width (&rng), range_height (&rng),
@@ -2865,9 +2879,9 @@ sheet_style_optimize (Sheet *sheet)
 		return;
 
 	data.ss = gnm_sheet_get_size (sheet);
-	data.debug = gnm_debug_flag ("style-optimize");
+	data.recursion = TRUE;
 
-	if (data.debug)
+	if (debug_style_optimize)
 		g_printerr ("Optimizing %s\n", sheet->name_unquoted);
 
 	verify = gnm_debug_flag ("style-optimize-verify");
