Refactoring and pep8