fixed infinite loop error with timeout