Changes to make PyLint (more) happy. Convert indents to spaces.
Improved logic to get a segmen. DRY.