consolidating heatmap code