Fix loop scope