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

    public typealias Index = CircularBuffer<Element>.Index

    private var buffer: CircularBuffer<Element>
    private var markedIndex: Index? = nil /* nil: nothing marked */

    /// Create a new instance.
    ///


    /// Returns true if the buffer has been marked at all.
    public var hasMark: Bool {
        return self.markedIndexOffset != nil
    }
}
