 M: model model-activated drop ;
 
 : ref-model ( model -- n )
-    dup model-ref 1+ dup rot set-model-ref ;
+    [ 1+ ] change-ref ref>> ;
 
 : unref-model ( model -- n )
-    dup model-ref 1- dup rot set-model-ref ;
+    [ 1- ] change-ref ref>> ;
 
 : activate-model ( model -- )
     dup ref-model 1 = [
-        dup model-dependencies
+        dup dependencies>>
         [ dup activate-model dupd add-connection ] each
         model-activated
     ] [


: deactivate-model ( model -- )
    dup unref-model zero? [
        dup model-dependencies
        [ dup deactivate-model remove-connection ] with each
    ] [
        drop

M: model hashcode* drop model hashcode* ;

: add-dependency ( dep model -- )
    dependencies>> push ;

: remove-dependency ( dep model -- )
    dependencies>> delete ;

DEFER: add-connection

