Converted to Python3

Not fully tested: base case seems to work