optimize so we dont do math.min every loop