Minor, but I'd prefer not to unnecessarily bind a val in a scope where it doesn't need to be used:
```scala
// Compute the minimum and the maximum from stats once
val (max, min) = { val sc = stats(); (sc.max, sc.min) } 
```