Fix histogram row index calculations