Maybe you could set iter_num as a function parameter too?