conformed relevant code portions to pep8, structural changes