fixed the stopping criteria