Fixed index out of bounds error in hist and cats handlers.