PEP 8 fixes. Remove dead code. Fix exceptions.