cleanup and PEP8-based code reformatting