diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 # Revision history for granite
 
+## 0.7.3.1 -- 2026-06-22
+* Fix kde computation of average
+
 ## 0.7.3.0 -- 2026-06-19
 * improved long text/axis display
 * flame graphs
diff --git a/granite.cabal b/granite.cabal
--- a/granite.cabal
+++ b/granite.cabal
@@ -1,6 +1,6 @@
 cabal-version:      3.0
 name:               granite
-version:            0.7.3.0
+version:            0.7.3.1
 synopsis:           Easy terminal plotting.
 description:        A terminal plotting library for quick and easy visualisation.
 license:            MIT
diff --git a/src/Granite/Stat.hs b/src/Granite/Stat.hs
--- a/src/Granite/Stat.hs
+++ b/src/Granite/Stat.hs
@@ -45,6 +45,7 @@
     Stat (..),
     SummaryFun (..),
  )
+import Data.Maybe (listToMaybe, fromMaybe)
 
 applyStat :: Stat -> Mapping -> DataFrame -> DataFrame
 applyStat stat m df = case stat of
@@ -107,7 +108,7 @@
     which :: [Double] -> Double -> Int
     which es v
         | length es < 2 = -1
-        | v + eps < head es = -1
+        | maybe False (v + eps <) (listToMaybe es) = -1
         | v > last es + eps = -1
         | otherwise = go 0
       where
@@ -150,7 +151,7 @@
 kdeData n xs =
     let nn = length xs
         mu = sum xs / fromIntegral nn
-        var = sum [(x - mu) ** 2 | x <- xs] / fromIntegral (max 1 (nn - 1))
+        var = sum [(x - mu) ^ (2 :: Int) | x <- xs] / fromIntegral (max 1 (nn - 1))
         sigma = sqrt (max var 1e-12)
         h = 1.06 * sigma * fromIntegral nn ** (-0.2)
         lo = minimum xs - 3 * h
@@ -311,11 +312,11 @@
                             then xs' !! (k `div` 2)
                             else (xs' !! (k `div` 2 - 1) + xs' !! (k `div` 2)) / 2
      in BoxStats
-            { yMin = head sorted
+            { yMin = fromMaybe 0 (listToMaybe sorted)
             , q1 = qq lower
             , med = m
             , q3 = qq upper
-            , yMax = last sorted
+            , yMax = fromMaybe 0 (listToMaybe (reverse sorted))
             }
 
 runCount :: Mapping -> DataFrame -> DataFrame
