Refactored, added logging, PEP8