implemented the fourth stopping criteria