Massive change to address most of the issues discovered by pylint.