Revised logic---new stopping criteria