fixing the use of global and local variables within iteration in GUI