Fix loop structure bug