Fixed a bunch of pylint errors.
Refactored code to reduce code redundency.