Refactored the segment to avoid having to pass the child elements around. Added direct tests for envelope.