Refactored histdata.js