More pep8 fixes and minor code improvements