endPosition is exclusive