diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@
 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
+## 0.22.5
+### Fixed
+- Cache was being completely pruned.
+
 ## 0.22.4
 ### Fixed
 - Cache now prunes correctly.
diff --git a/haskoin-store.cabal b/haskoin-store.cabal
--- a/haskoin-store.cabal
+++ b/haskoin-store.cabal
@@ -4,10 +4,10 @@
 --
 -- see: https://github.com/sol/hpack
 --
--- hash: 4792e70aaa8e9b47c7367de22ef0739cf5538f5c878468351f030e037658f560
+-- hash: 2cd6a8e51e70eea8c49ec7ce774c829045c2c0df5f1727af547d6194e05db79c
 
 name:           haskoin-store
-version:        0.22.4
+version:        0.22.5
 synopsis:       Storage and index for Bitcoin and Bitcoin Cash
 description:    Store and index Bitcoin or Bitcoin Cash blocks, transactions, balances and unspent outputs.
                 All data is available via REST API in JSON or binary format.
diff --git a/src/Haskoin/Store/Cache.hs b/src/Haskoin/Store/Cache.hs
--- a/src/Haskoin/Store/Cache.hs
+++ b/src/Haskoin/Store/Cache.hs
@@ -21,7 +21,8 @@
     ) where
 
 import           Control.DeepSeq           (NFData)
-import           Control.Monad             (forM, forM_, forever, unless, void)
+import           Control.Monad             (forM, forM_, forever, unless, void,
+                                            when)
 import           Control.Monad.Logger      (MonadLoggerIO, logDebugS, logErrorS,
                                             logInfoS, logWarnS)
 import           Control.Monad.Reader      (ReaderT (..), asks)
@@ -346,11 +347,13 @@
     return $ do
         ys <- map (\(x, s) -> (, s) <$> decode x) <$> xs
         return (rights ys)
-getFromSortedSet key Nothing offset (Just count) = do
-    xs <- zrangeWithscores key offset (offset + count - 1)
-    return $ do
-        ys <- map (\(x, s) -> (, s) <$> decode x) <$> xs
-        return (rights ys)
+getFromSortedSet key Nothing offset (Just count)
+    | count <= 0 = return (pure [])
+    | otherwise = do
+        xs <- zrangeWithscores key offset (offset + count - 1)
+        return $ do
+            ys <- map (\(x, s) -> (, s) <$> decode x) <$> xs
+            return (rights ys)
 getFromSortedSet key (Just score) offset Nothing = do
     xs <-
         zrangebyscoreWithscoresLimit
@@ -435,19 +438,22 @@
     if s > x
         then do
             n <- flush (s - x)
-            $(logDebugS) "Cache" $ "Pruned " <> cs (show n) <> " keys"
+            when (n > 0) $
+                $(logDebugS) "Cache" $ "Pruned " <> cs (show n) <> " keys"
             return n
         else return 0
   where
     flush n =
-        runRedisReply $ do
-            let x = min 1000 (n `div` 64)
-            eks <- getFromSortedSet maxKey Nothing 0 (Just x)
-            case eks of
-                Right ks -> do
-                    xs <- sequence <$> forM (map fst ks) redisDelXPubKeys
-                    return $ xs >>= return . sum
-                Left _ -> return $ eks >> return 0
+        runRedisReply $
+        case min 1000 (n `div` 64) of
+            0 -> return (pure 0)
+            x -> do
+                eks <- getFromSortedSet maxKey Nothing 0 (Just x)
+                case eks of
+                    Right ks -> do
+                        xs <- sequence <$> forM (map fst ks) redisDelXPubKeys
+                        return $ xs >>= return . sum
+                    Left _ -> return $ eks >> return 0
 
 touchKeys :: Real a => a -> [XPubSpec] -> RedisReply Integer
 touchKeys _ [] = return (pure 0)
@@ -903,8 +909,7 @@
 addrsToAdd xbals gap addrinfo =
     let headi = head (addressXPubPath addrinfo)
         maxi =
-            maximum $
-            map (head . tail . xPubBalPath) $
+            maximum . (0 :) . map (head . tail . xPubBalPath) $
             filter ((== headi) . head . xPubBalPath) xbals
         xpub = addressXPubSpec addrinfo
         newi = head (tail (addressXPubPath addrinfo))
