diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -51,3 +51,7 @@
 ## 0.1.0.12 -- 2022-11-23
 
 * Added Full-text Minute-space index (FM-index) implementation.
+
+## 0.1.0.13 -- 2022-11-23
+
+* Bug fixes to FM-index STRef functions.
diff --git a/src/Data/FMIndex/Internal.hs b/src/Data/FMIndex/Internal.hs
--- a/src/Data/FMIndex/Internal.hs
+++ b/src/Data/FMIndex/Internal.hs
@@ -53,7 +53,8 @@
 import Data.Foldable()
 import Data.List()
 import Data.Maybe()
-import Data.Sequence as DS (Seq(..),empty,(|>))
+import Data.Sequence as DS (Seq(..),ViewR(..),empty,(|>))
+import Data.Sequence.Internal as DSI
 import Data.STRef as DSTR
 import Data.Text as DText
 import GHC.Generics (Generic)
@@ -93,8 +94,10 @@
                      -> (Int,Int,Maybe ByteString)
                      -> ST s ()
 updateSTFMIndexSeqAB s e = do
-  (s2 DS.:|> s2fm) <- readSTRef s
-  writeSTRef s (s2 DS.|> (((\(a,_) -> a) s2fm),((\(_,b) -> b) s2fm) DS.|> e))
+  s2 <- readSTRef s
+  case viewr s2 of
+    EmptyR           -> pure ()
+    (s2h DS.:> s2fm) -> writeSTRef s (s2h DS.|> (((\(a,_) -> a) s2fm),((\(_,b) -> b) s2fm) DS.|> e))
 
 -- | State function to update 'FMIndexSeqB'
 -- with each step of the FMIndex.
@@ -226,8 +229,10 @@
                      -> (Int,Int,Maybe Text)
                      -> ST s ()
 updateSTFMIndexSeqAT s e = do
-  (s2 DS.:|> s2fm) <- readSTRef s
-  writeSTRef s (s2 DS.|> (((\(a,_) -> a) s2fm),((\(_,b) -> b) s2fm) DS.|> e))
+  s2 <- readSTRef s
+  case viewr s2 of
+    EmptyR           -> pure ()
+    (s2h DS.:> s2fm) -> writeSTRef s (s2h DS.|> (((\(a,_) -> a) s2fm),((\(_,b) -> b) s2fm) DS.|> e))
 
 -- | State function to update 'FMIndexSeqT'
 -- with each step of the FMIndex.
diff --git a/text-compression.cabal b/text-compression.cabal
--- a/text-compression.cabal
+++ b/text-compression.cabal
@@ -20,7 +20,7 @@
 -- PVP summary:     +-+------- breaking API changes
 --                  | | +----- non-breaking API additions
 --                  | | | +--- code changes with no API change
-version:            0.1.0.12
+version:            0.1.0.13
 
 -- A short (one-line) description of the package.
 synopsis:           A text compression library.
