my problem is that allInstances is already a set and has a different order each time it is called. Putting it into an ordered set could help while the program is running as I would get a temporary order. The problem is that I need to have the same order even if I restart the program in between. Ordering by something like a name could help. I think I will walk the model manually and collect the instances.