fix range checking in histogram indexing