changed while loop to not recreate objects each itteration