Optimisation: append_sample/6 is a hotspot. So in the fine stats case don't pget so much in there, just go through entries in order. And don't recalculate ceil/1 all the time.