made a few optimizations to heatmap.py