Refactored according to PEP8 and optimized imports