fix some off-by-one errors in histogram calculation