pep8/pyflakes clean up

Also changed how exceptions are raised.