Pylint-related fixes: bare exceptions, reuse of variable names, etc.