Refactored some code according to PEP