Circumvent python 3 recursion error