 PRIVATE>
 
 : (selected-rows) ( table -- {row} )
-    [ selected-indices>> ] keep
-    [ nth-row [ 1array ] [ drop { } ] if ] curry map concat ;
+    [ selected-indices>> keys natural-sort ] keep
+    '[ _ nth-row [ 1array ] [ drop { } ] if ] map concat ;
 
 : selected-rows ( table -- {value} )
-    [ (selected-rows) ] [ renderer>> ] bi [ row-value ] curry map ;
+    [ (selected-rows) ] [ renderer>> ] bi '[ _ row-value ] map ;
+
 : (selected-row) ( table -- value/f ? ) (selected-rows) multiple>single ;
+
 : selected-row ( table -- value/f ? ) selected-rows multiple>single ;
 
 <PRIVATE
 
 : set-table-model ( model value multiple? -- )
-    [ multiple>single* ] unless swap set-model ;
+    [ multiple>single drop ] unless swap set-model ;
 
 : update-selected ( table -- )
-    [ [ selection>> ] [ selected-rows ] [ multiple-selection?>> ] tri set-table-model ]
-    [
-        [ selection-index>> ] [ selected-indices>> ] [ multiple-selection?>> ] tri
+    [
+        [ selection>> ]
+        [ selected-rows ]
+        [ multiple-selection?>> ] tri
+        set-table-model
+    ]
+    [
+        [ selection-index>> ]
+        [ selected-indices>> ]
+        [ multiple-selection?>> ] tri
         set-table-model
     ] bi ;
 


: draw-selected-rows ( table -- )
    {
        { [ dup selected-indices>> empty? ] [ drop ] }
        [
            [ selected-indices>> ] [ selection-color>> gl-color ] [ ] tri
            [ swap row-bounds gl-fill-rect ] curry each
        ]
    } cond ;

:: row-font ( row ind table -- font )
    table font>> clone
    row table renderer>> row-color [ >>foreground ] when*
    ind table selected-indices>> key?
    [ table selection-color>> >>background ] when ;

: draw-columns ( columns widths alignment font gap -- )
    '[ [ _ ] 3dip _ draw-column ] 3each ;
