Add utils.histogram and fix some bugs