     ] when dupd remove! push ;
 
 : gemini-history ( -- )
-    HISTORY [ 1 + swap "[%s] %s\n" printf ] each-index
+    HISTORY [ 1 + swap "[%d] %s\n" printf ] each-index
     LINKS delete-all HISTORY LINKS push-all ;
 
 : gemini-print ( url body meta -- )
     f pre [
-        LINKS delete-all
+        PAGE delete-all
         gemini-charset decode string-lines [
             { [ pre get not ] [ "=>" ?head ] } 0&& [
-                swap gemini-link present LINKS push
-                LINKS length swap "[%s] %s\n" printf
+                swap gemini-link present over 2array PAGE push
+                PAGE length swap "[%s] %s\n" printf
             ] [
                 gemini-line.
             ] if
         ] with each
+        LINKS delete-all PAGE keys LINKS push-all
     ] with-variable ;
 
 : gemini-get ( args -- )

        { abbrevs { "l" } } }
    T{ command
        { name "ls" }
        { quot [ drop gemini-ls ] }
        { help "List the currently available links." }
        { abbrevs f } }
    T{ command

        "less" swap 2array try-process
    ] [ drop ] if ;

 : gemini-ls ( args -- )
    PAGE swap "-l" = '[
        1 + swap first2 swap
        _ [ " (" ")" surround ] [ drop f ] if
        "[%d] %s%s\n" printf
    ] each-index
    LINKS delete-all PAGE keys LINKS push-all ;

: gemini-quit ( -- )
    "gemini.txt" temp-file ?delete-file 0 exit ;
