fix histogram bug, add tests