diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm
index 2760fa6f2..716007430 100644
--- a/lib/Slic3r/Print/Object.pm
+++ b/lib/Slic3r/Print/Object.pm
@@ -344,7 +344,9 @@ sub discover_horizontal_shells {
                 Slic3r::debugf "Layer %d has %d surfaces of type '%s'\n",
                     $i, scalar(@surfaces), ($type == S_TYPE_TOP ? 'top' : 'bottom');
                 
-                my $solid_layers = S_TYPE_TOP ? $Slic3r::Config->top_solid_layers : $Slic3r::Config->bottom_solid_layers;
+                my $solid_layers = ($type == S_TYPE_TOP)
+                    ? $Slic3r::Config->top_solid_layers
+                    : $Slic3r::Config->bottom_solid_layers;
                 for (my $n = $type == S_TYPE_TOP ? $i-1 : $i+1; 
                         abs($n - $i) <= $solid_layers-1; 
                         $type == S_TYPE_TOP ? $n-- : $n++) {