attempt at implemeting stopping criteria