In these cases I always worry about endless loops in weird cases
(This is not inside Fortran so Ctrl+C will still work.)

replace with `for _ in range(maxiter)` with maxiter = 1000?