Made it compatible with Python3, made a bit modification around 'except'