diff --git a/inc/lektor/net.h b/inc/lektor/net.h
index 7741dba464badfb3435ff3df8c2cb55a27460e81..0b29e70f41dcafa1f28fc3e345d1863bcba9b975 100644
--- a/inc/lektor/net.h
+++ b/inc/lektor/net.h
@@ -50,7 +50,7 @@ void lkt_state_send(struct lkt_state *srv, size_t c, struct lkt_message *msg);
 /* Get and set continuation state for a client. */
 size_t lkt_remaining_msg(struct lkt_state *srv, size_t c);
 
-bool lkt_get_continuation(struct lkt_state *srv, size_t c);
+int lkt_get_continuation(struct lkt_state *srv, size_t c);
 void lkt_set_continuation(struct lkt_state *srv, size_t c, int i);
 
 /* Get the mask to watch for events for a given client, to be used with the `idle` command.
diff --git a/src/commands.c b/src/commands.c
index 69bbec25cae7fdb3e181f1920cfcf17c7c5fc6b2..2ed168f5cf4141dbf6638aaf505acb50c91a91c8 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -958,11 +958,11 @@ only_one:
 
     /* The command is used with a range specifier. */
 is_a_range:
-    if (to - from < lkt_remaining_msg(srv, c) - 1) {
+    if (to - from + 1 < lkt_remaining_msg(srv, c) - 2) {
         lkt_set_continuation(srv, c, 0);
         return database_queue_list(srv->db, from, to, &callback);
     } else {
-        to = from + lkt_remaining_msg(srv, c) - 2;
+        to = from + lkt_remaining_msg(srv, c) - 3;
         lkt_set_continuation(srv, c, to + 1);
         return database_queue_list(srv->db, from, to, &callback);
     }
diff --git a/src/main/lkt.c b/src/main/lkt.c
index db26aea6ff0eec94ead577d82f76a00d1f8b88ae..834aa48311818e785cfbc4133b37aed220fef297 100644
--- a/src/main/lkt.c
+++ b/src/main/lkt.c
@@ -598,7 +598,6 @@ list__(struct lkt_cmd_args *args)
 
     FILE *sock = NULL;
 redo:
-    printf("%ld:%ld\n", continuation, up);
     sock = lkt_connect();
     if (up != 0)
         write_socket_format(sock, "playlist %d:%d\n", continuation, up);
diff --git a/src/net/listen.c b/src/net/listen.c
index 51bb903157ac693f8a1a1021f9dad150a5bdd65d..216e1d75e5fa5168d59d1f0b2aaa49aa9a362ef6 100644
--- a/src/net/listen.c
+++ b/src/net/listen.c
@@ -63,7 +63,7 @@ lkt_close_client(struct lkt_state *srv, size_t c)
     return srv->clients[c - 1].request_close = true;
 }
 
-inline bool
+inline int
 lkt_get_continuation(struct lkt_state *srv, size_t c)
 {
     return srv->clients[c - 1].continuation;