Converted code to Python 3