     public typealias Index = CircularBuffer<Element>.Index
 
     private var buffer: CircularBuffer<Element>
-    private var markedIndex: Index? = nil /* nil: nothing marked */
+    private var markedIndexOffset: Int? = nil /* nil: nothing marked */
 
     /// Create a new instance.
     ///

    public mutating func mark() {
        let count = self.buffer.count
        if count > 0 {
            self.markedIndex = self.endIndex.advanced(by: -1)
        } else {
            assert(self.markedIndex == nil, "marked index is \(self.markedIndex.debugDescription)")
        }
    }


    /// Removes the first element from the buffer.
    public mutating func removeFirst() -> Element {
        assert(self.buffer.count > 0)
        if let markedIndex = self.markedIndexOffset {
            if self.startIndex.advanced(by: markedIndex) == self.startIndex {
                self.markedIndexOffset = nil
            } else {
                if let markedIndexOffset = self.markedIndexOffset {
                    self.markedIndexOffset = markedIndexOffset - 1
                }
            }
        }
        return self.buffer.removeFirst()
