add stop criteria function