Made some comparisons more pythonic
Further code tidy up to appease PyCharm static analysis.