Improve the stop condition