fixed loop issues