FIX pep8 pylint and minor refactoring