PEP 8 changes and refactoring