exception handling change to Python 3 and PEP 8