Drop pylint:disable directives, refactor code

Drop several `pylint:disable` directives:

1. W0621 (redefining-name-from-outer-scope)
2. W0632 (possible-unbalanced-tuple-unpacking-with-sequence)
3. R0914 (too-many-local-variables)

Fix the the first issue. The second issue was fixed by
f4cbc54ae61d77837ce6e73455bba1f47898c75a. The third warning is still a
legitimate issue, and uncommenting the warning reinforces the fact that the code
has design issues.

Wrap the module's business logic in an `if __name__ == '__main__'` conditional.
This prevents the functions in the module from executing when the module is
imported. This is a first step in making it possible to write side-effect-free
unit tests.