small refinements to histogram function