Maybe break out of the loop easly as soon as you hit the max?