Added a stop condition to exit