pep8, fixes, refactoring