 : increment-gap-start ( gb n -- )
     over gap-start>> + swap gap-start<< ;
 
-! generic dispatch identifies numbers as sequences before numbers...
-M: number insert* ( elem position gb -- ) [ 1array ] 2dip insert* ;
-! : number-insert ( num position gb -- ) [ 1array ] 2dip insert* ;
-
-M: sequence insert* ( seq position gb -- )
+M: number insert*
+    [ 1array ] 2dip insert* ;
+
+M: sequence insert*
     prepare-insert [ insert-elements ] 2keep swap length increment-gap-start ;
 
-: (delete*) ( gb -- )
-    dup gap-end>> 1 + over gap-end<< ?decrease ;
-
-GENERIC: delete* ( pos gb -- )
-
-M: gb delete* ( position gb -- )
-    tuck move-gap (delete*) ;
+: delete* ( pos gb -- )
+    tuck move-gap dup gap-end>> 1 + over gap-end<< ?decrease ;
 
 ! -------- stack/queue operations -----------
 

    [ expand-factor>> * ceiling >fixnum ]
    [ min-size>> ] bi max ;

: <gb> ( seq -- gb )
    gb new
        5 >>min-size
        1.5 >>expand-factor
        swap
        [ length >>gap-start ] keep
        [ length over required-space >>gap-end ] keep
        over gap-end>> swap { } like resize-array <circular> >>seq ;

M: gb like ( seq gb -- seq ) drop <gb> ;

: gap-length ( gb -- n ) [ gap-end>> ] keep gap-start>> - ;

: buffer-length ( gb -- n ) seq>> length ;

M: gb length ( gb -- n ) [ buffer-length ] keep gap-length - ;

: valid-position? ( pos gb -- ? )
    ! one element past the end of the buffer is a valid position when we're inserting
    length -1 swap between? ;

: valid-index? ( i gb -- ? )
    buffer-length -1 swap between? ;

ERROR: position-out-of-bounds position gap-buffer ;


    dup gap-start>> head ;

: copy-after-gap ( array gb -- )
    ! copy everything after the gap in 'gb' into the end of
    ! 'array', and change 'gb's gap-end to reflect the gap-end
    ! in 'array'
    dup after-gap [ 2dup set-new-gap-end gap-end>> swap ] dip -rot copy ;

: copy-before-gap ( array gb -- )
    ! copy everything before the gap in 'gb' into the start of
    ! 'array'
    before-gap 0 rot copy ; ! gap start doesn't change

: resize-buffer ( gb new-size -- )
