Segment query support

Unfinished