stop loops after MAX_ITERATIONS loops