Fix loop issue