Upgraded code to python 3