Fixed errors and refactor for PEP8