If you wait for the app to have loaded (see the comment on line #38) then you don't need to do this loop