Topological order

The idea is to sort addins in a topological order. Each addin can define one of five things for _order_:
* `>X` - I must be immediately after the addin with id X

* `>>X` - I must be somewhere after the addin with id X (but not necessarily immediately) 

* `<X`- I must be immediately before the addin with id X

* `<<X` - I must be somewhere before the addin with id X (but not necessarily immediately) 

* `Number` - A numerical order which is used if none of the above is applicable


you have several loops using these sort of "global" i j k variables, which i'm against.
if you don't want to do if functional style which makes these irrelevant, i suggest separating each such loop into an abstract step by calling a private function.
this function can define the variable it needs internally and you won't have any risks from the reuse of loop variables.