Fixed loop issues