More code cleanup and PEP8 fixes