Segment query support
general tidying
Segment JSON serialization