fixed the loop