fixing loop on threads