facelessuser, thanks for your hard work. The problem with the wrong indexing after closing all tabs or the program window has been solved. But still there is a problem with updating the idnexing queue if tabs are rearranged. In my previous example:
Open (or activate) in order: 1,2,3,4,5,6,7
then activate 2 and move it a few places, e.g. after 5 and before 6. After closing 2, 1 gets the focus instead of 7.