Fix an exception when opening Bundle Editor

Caused by an earlier commit of mine.
Roll some duplicate code into a loop

(so the compiler can unroll it again)