Clean up some code based on PyCharm code inspection report