updated main next with stopped condition