Refactored stopping criteria.