replaced while(true)