Fixed a bug in the stopping criteria.