refactored heatmap javascript