Improvements to histgram binning with discrete data. Fixes #400.