pep8 and refactor functions