Half-baked changes to compute histogram. Doesn't work yet.