attempt at implementing stopping criteria