Refactoring for pep8
Fixing exception handling for Python 3
Fixing print for Python 3