diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 # Revision history for popkey
 
+# 0.1.0.1
+- Fix bug in sum decoding due to conflating 0 and 1-based positions
+
 ## 0.1.0.0
 - Drop profunctor instance in exchange for keyed folding
 - Add Store instance
diff --git a/popkey.cabal b/popkey.cabal
--- a/popkey.cabal
+++ b/popkey.cabal
@@ -1,6 +1,6 @@
 cabal-version:       2.4
 name:                popkey
-version:             0.1.0.0
+version:             0.1.0.1
 synopsis:            Static key-value storage backed by poppy
 description:         Static key-value storage backed by poppy.
 homepage:            https://github.com/identicalsnowflake/popkey
diff --git a/src/PopKey/Encoding.hs b/src/PopKey/Encoding.hs
--- a/src/PopKey/Encoding.hs
+++ b/src/PopKey/Encoding.hs
@@ -99,7 +99,7 @@
   gpkEncode (L1 x) = Sum' (Left (gpkEncode @s x))
   gpkEncode (R1 x) = Sum' (Right (gpkEncode @s x))
   {-# INLINE gpkDecode #-}
-  gpkDecode (Sum' x)= case x of
+  gpkDecode (Sum' x) = case x of
     Left l -> L1 (gpkDecode @s l)
     Right r -> R1 (gpkDecode @s r)
 
diff --git a/src/PopKey/Internal2.hs b/src/PopKey/Internal2.hs
--- a/src/PopKey/Internal2.hs
+++ b/src/PopKey/Internal2.hs
@@ -62,10 +62,10 @@
     go (Single pk) = Single' (pkIndex pk i)
     go (Prod x y) = Prod' (go x) (go y)
     go (Sum _ pk l r) = do
-      let b1pos = fromIntegral i + 1
-      if pk .?. b1pos
-         then Sum' (Right (rawq (fromIntegral (rank1 pk (fromIntegral b1pos) - 1)) r))
-         else Sum' (Left (rawq (fromIntegral (rank0 pk (fromIntegral b1pos) - 1)) l))
+      let b1pos = fromIntegral i
+      if pk .?. b1pos -- nasty! this uses 0-based indexing, while rank/select use 1-based indexing
+         then Sum' (Right (rawq (fromIntegral (rank1 pk (fromIntegral b1pos))) r))
+         else Sum' (Left (rawq (fromIntegral (rank0 pk (fromIntegral b1pos))) l))
 
 -- returns @-1@ if not found
 {-# INLINABLE bin_search2 #-}
@@ -123,12 +123,12 @@
             v <- MUV.new l
 
             for_ (zip [ 0 .. ] zs) \(i,x) -> case x of
-              Left _ -> pure ()
+              Left _ -> MUV.unsafeWrite v i 0
               Right _ -> MUV.unsafeWrite v i 1
 
             UV.unsafeFreeze v
 
-          uv64 :: UV.Vector Word64 = unsafeCoerce do cloneToWords bv
+          uv64 :: UV.Vector Word64 = unsafeCoerce do cloneToWords $ bv
           sv64 :: SV.Vector Word64 = SV.convert uv64
 
           !(ppy :: CsPoppy) = makeCsPoppy sv64
diff --git a/test/Spec.hs b/test/Spec.hs
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -19,7 +19,7 @@
     it "sanity checks for fixed-size data" $ property \(xs :: [ Int ]) ->
       toList (scode $ fmap (+1) $ makePopKey' xs) == fmap (+1) xs
 
-    it "sanity checks for fixed-size data" $ property \(xs :: [ (Int , Word8) ]) ->
+    it "sanity checks for fixed-size data" $ property \(xs :: [ (Int , Maybe Word8) ]) ->
       toList (scode $ makePopKey' xs) == xs
 
     it "sanity checks for var-size data" $ property \(xs :: [ [ Int ] ]) ->
