Everybody is getting a Main ID when you purchase your 1st position in Level 1, this ID will always stay the same through all Levels. Now, when you upgrade your account, the script is looking for your Direct Sponsor's Main ID, in order to figure out where to place your position and WHO to make the payment to.
Then, depending on which level you are making the payment for, it looks up either 1, 2 or 3 positions within THAT level to know who should receive the payment!
IF your upline is NOT upgraded at all at those levels (or their levels are already filled), it will keep searching until such time NO member can be found and then the payment will go to admin.
That's why you should always contact your up-line if he/she has NOT upgraded yet to the same level and give them a chance to do so BEFORE you upgrade or otherwise they may miss out on income! You can check the current levels of your upline on the Upgrade Account page