diff --git a/test/nm-online.c b/test/nm-online.c
index 91168bd..c209142 100644
--- a/test/nm-online.c
+++ b/test/nm-online.c
@@ -45,14 +45,15 @@
 #define PROGRESS_STEPS 15
 #define WAIT_STARTUP_TAG "wait-startup"
 
 typedef struct
 {
 	gint64 start_timestamp_ms;
 	gint64 end_timestamp_ms;
+	gint64 progress_step_duration;
 	gboolean quiet;
 } Timeout;
 
 static void
 client_properties_changed (GObject *object,
                            GParamSpec *pspec,
                            gpointer loop)
@@ -76,25 +77,24 @@ client_properties_changed (GObject *object,
 	}
 }
 
 static gboolean
 handle_timeout (gpointer data)
 {
 	Timeout *timeout = data;
-	gint64 now = g_get_monotonic_time () / (G_USEC_PER_SEC / 1000);
+	const gint64 now = g_get_monotonic_time () / (G_USEC_PER_SEC / 1000);
 	gint64 remaining_ms = timeout->end_timestamp_ms - now;
+	const gint64 elapsed_ms = now - timeout->start_timestamp_ms;
 	int progress_next_step_i = 0;
 
 	if (!timeout->quiet) {
 		int i;
-		double percentage = ((double) (now - timeout->start_timestamp_ms)) / (timeout->end_timestamp_ms - timeout->start_timestamp_ms);
-		/* it holds: (percentage >= 0); */
 
 		/* calculate the next step (not the current): floor()+1 */
-		progress_next_step_i = ((int) (percentage * PROGRESS_STEPS)) + 1;
+		progress_next_step_i = (elapsed_ms / timeout->progress_step_duration) + 1;
 		progress_next_step_i = MIN (progress_next_step_i, PROGRESS_STEPS);
 
 		g_print (_("\rConnecting"));
 		for (i = 0; i < PROGRESS_STEPS; i++)
 			putchar (i < progress_next_step_i ? '.' : ' ');
 		g_print (" %4lds", (long) (MAX (0, remaining_ms) / 1000));
 		fflush (stdout);
@@ -104,28 +104,27 @@ handle_timeout (gpointer data)
 		if (!timeout->quiet)
 			g_print ("\n");
 		exit (1);
 	}
 
 	if (!timeout->quiet) {
 		gint64 rem;
-		gint64 progress_step_duration = (timeout->end_timestamp_ms - timeout->start_timestamp_ms + PROGRESS_STEPS/2) / PROGRESS_STEPS;
 
 		/* synchronize the timeout with the ticking of the seconds. */
 		rem = remaining_ms % 1000;
 		if (rem <= 3)
 			rem = rem + G_USEC_PER_SEC;
 		rem = rem + 10; /* add small offset to awake a bit after the second ticks */
 		if (remaining_ms > rem)
 			remaining_ms = rem;
 
 		/* synchronize the timeout with the steps of the progress bar. */
-		rem = (progress_next_step_i * progress_step_duration) - (now - timeout->start_timestamp_ms);
+		rem = (progress_next_step_i * timeout->progress_step_duration) - elapsed_ms;
 		if (rem <= 3)
-			rem = rem + progress_step_duration;
+			rem = rem + timeout->progress_step_duration;
 		rem = rem + 10; /* add small offset to awake a bit after the time out */
 		if (remaining_ms > rem)
 			remaining_ms = rem;
 	}
 
 	g_timeout_add (remaining_ms, handle_timeout, timeout);
 	return G_SOURCE_REMOVE;
@@ -228,14 +227,15 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
 	g_signal_connect (client, "notify",
 	                  G_CALLBACK (client_properties_changed), loop);
 
 	timeout.end_timestamp_ms = timeout.start_timestamp_ms + remaining_ms;
+	timeout.progress_step_duration = (timeout.end_timestamp_ms - timeout.start_timestamp_ms + PROGRESS_STEPS/2) / PROGRESS_STEPS;
 
 	g_timeout_add (timeout.quiet ? remaining_ms : 0,
 	               handle_timeout, &timeout);
 
 	g_main_loop_run (loop);
 	g_main_loop_unref (loop);
 
