fixed crazy loop issues