Fix minor bug in detect_segments that was leading to 0-length encounters.