PEP8 styled, refactored code