fixed loop not ending