Fixed compliance with pep8 and reduced complexity