diff --git a/src/winio.c b/src/winio.c
index 7158dd75eeda543069c0a4648167d6b7556ca2bf..06bc5d2f997672d99acfda16dec68ec85990cdf8 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2810,21 +2810,22 @@ void compute_maxrows(void)
 {
 #ifndef NANO_TINY
     if (ISSET(SOFTWRAP)) {
-	int n;
-	filestruct *foo = openfile->edittop;
+	int screenrow;
+	filestruct *line = openfile->edittop;
 
 	maxrows = 0;
-	for (n = 0; n < editwinrows && foo; n++) {
+
+	for (screenrow = 0; screenrow < editwinrows && line != NULL; screenrow++) {
+	    screenrow += strlenpt(line->data) / editwincols;
+	    line = line->next;
 	    maxrows++;
-	    n += strlenpt(foo->data) / editwincols;
-	    foo = foo->next;
 	}
 
-	if (n < editwinrows)
-	    maxrows += editwinrows - n;
+	if (screenrow < editwinrows)
+	    maxrows += editwinrows - screenrow;
 
 #ifdef DEBUG
-	fprintf(stderr, "compute_maxrows(): maxrows = %d\n", maxrows);
+	fprintf(stderr, "recomputed: maxrows = %d\n", maxrows);
 #endif
     } else
 #endif /* !NANO_TINY */