hmm maybe instead of using a global return a tuple (resulting, max_line_digits) and then you just pass it around?