Implementing stopping criteria.