updated the loop structure