Code refactor for PEP best practices