Refactored code to conform to pep8 standards and added docstrings.