code cleanup and pep8 fixes