fix looping in the new code