Converted the code to Python3