Make max iterations configurable.
Clamp values so they don't overflow