Fix indexing bug building histogram