revise recursion in python